Write the assembler program using LMC assembler to do the sa
Write the assembler program using LMC assembler to do the same as the C code below
int main(){
int x = 6; int y = 44;
while (x >= 0) {
y++;
x--;
}
if (x < 0)
y = -1;
else
y = 1;
if (x == 0)
y = -1;
else
y = 1;
if (x == 3)
y = -1;
else
y = 1;
}
When this is completed change your LMC assembler to take input instead of x and y having a fixed value.
to check code here: http://peterhigginson.co.uk/LMC/
Here is a link to a PDF that will help
http://www.ictresources.net/uploads/2/9/2/6/29262609/the_little_man_computer.pdf
Solution
main:
stwu 1,-48(1)
stw 31,44(1)
mr 31,1
li 9,6
stw 9,24(31)
li 9,44
stw 9,28(31)
b .L2
.L3:
lwz 9,28(31)
addi 9,9,1
stw 9,28(31)
lwz 9,24(31)
addi 9,9,-1
stw 9,24(31)
.L2:
lwz 9,24(31)
cmpwi 7,9,0
bge 7,.L3
lwz 9,24(31)
cmpwi 7,9,0
bge 7,.L4
li 9,-1
stw 9,28(31)
b .L5
.L4:
li 9,1
stw 9,28(31)
.L5:
lwz 9,24(31)
cmpwi 7,9,0
bne 7,.L6
li 9,-1
stw 9,28(31)
b .L7
.L6:
li 9,1
stw 9,28(31)
.L7:
lwz 9,24(31)
cmpwi 7,9,3
bne 7,.L8
li 9,-1
stw 9,28(31)
b .L9
.L8:
li 9,1
stw 9,28(31)
.L9:
li 9,0
mr 3,9
addi 11,31,48
lwz 31,-4(11)
mr 1,11
blr


