I'm having some trouble translating the following C++ program to Pep/8 assembly language. Can anyone help me solve this. This is what I have come up with.

#include <iostream>
using namespace std;

int list[16];
int i, numItems;
int temp;

int main()
	{
	cin >> numItems;
	for (i = 0; i < numItems; i++)
	{
		cin >> list[i];
	}
	
	temp = list[0];
	for (i = 0; i < numItems; i++)
	{
		list[i] = list[i + 1];
	}
	list[numItems - 1] = temp;
	for (i = 0; i < numItems; i++)
	{
		cout << list[i] << ' ';
	}
	cout << endl;
	return 0;
}

Pep/8 assembly

BR	main
list:		.BLOCK	32	;global variable
i:		.BLOCK	2	;global variable
numItems:	                .BLOCK	2              ;global variable
temp:		.BLOCK	2	;global variable
;
;************** main()
main:		DECI        numItems,d   ;cin >> numItems
		LDX	0,i	;for (i = 0	
		STX	i,d
for1:		CPX	numItems,;i < numItems
		BRGE	endFor1
		ASLX		;an integer has two bytes
		DECI	list,x	;cin >> list[i]
		LDX	i,d	;i++
		ADDX	1,i
		STX 	i,d
		BR	for1
endFor1:	                ASLX
		LDX	list,x	;temp = list[0]
		STX	temp,d
		CPX	0,i	;for (i = 0
		STX	i,d
for2:		CPX	numItems,	;i < numItems - 1
		SUBX	1,i		
		BRGE	endFor2
		ASLX		;an integer has two bytes
		LDX	list,x     	;list[i] = list[i + 1]
		ADDX	1,i		
		STX	list,d
		LDX	i,d
		ADDX	1,i	;i++)
		STX	i,d
		BR	for2
endFor2:	                ASLX	;an integer has two bytes
		LDX	temp,x	;list[ numItems - 1] = temp
		STX	list,d
		SUBX	1,i
		LDX	0,i	;for (1 = 0
		STX	i,d
for3:		CPX	numItems,i;i < numItems
		BRGE	endFor3
		ASLX		;an integer has two bytes
		DECO	list,x	;cout << list[i]
		CHARO	' ',i	;<< ' '
		LDX 	i,d	;i++)
		ADDX	1,i		
		STX	i,d
		BR	for3
		CHARO	'\n',i	;cout << endl
endFor3:	                STOP
		.END

I can't claim to know Pep/8 assembly, but it looks like you're not indexing the array properly.

Did you ever get this working? I'm curious what your final Pep/8 assembly looks like.

Did you ever get this working? I'm curious what your final Pep/8 assembly looks like.

Did anyone get this working in PEP8?

I am having issues converting this C++ to assembly in PEP8, any help would be appreciated.

#include <iostream>
using namespace std;

int main () {
int numItms, j, data, sum;
cin >> numItms;
sum = 0
for (j = 1; j <= numItms; j++) {
cin >> data;
sum += data;
}
cout << "Sum: " << sum << end1;
return -;
}

thanks

Edited 6 Years Ago by WaltP: Added CODE Tags

This article has been dead for over six months. Start a new discussion instead.