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