Little Man Cumputer assembly language code Q Write the assem

Little Man Cumputer assembly language code

Q. Write the assembler program using Little Man Cumputer 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.

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

to test code here: http://peterhigginson.co.uk/LMC/

Note: the code should look like something like that, post a screenshot after you test the code on the link above

   INP
        STA 99
        INP
        ADD 99
        OUT
        HLT

Solution

Answer:

Assembly Language Code:

.zero 1
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 6
mov DWORD PTR [rbp-8], 44
.L3:
cmp DWORD PTR [rbp-4], 0
js .L2
add DWORD PTR [rbp-8], 1
sub DWORD PTR [rbp-4], 1
jmp .L3
.L2:
cmp DWORD PTR [rbp-4], 0
jns .L4
mov DWORD PTR [rbp-8], -1
jmp .L5
.L4:
mov DWORD PTR [rbp-8], 1
.L5:
cmp DWORD PTR [rbp-4], 0
jne .L6
mov DWORD PTR [rbp-8], -1
jmp .L7
.L6:
mov DWORD PTR [rbp-8], 1
.L7:
cmp DWORD PTR [rbp-4], 3
jne .L8
mov DWORD PTR [rbp-8], -1
jmp .L9
.L8:
mov DWORD PTR [rbp-8], 1
.L9:
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L13
cmp DWORD PTR [rbp-8], 65535
jne .L13
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L13:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret

Little Man Cumputer assembly language code Q. Write the assembler program using Little Man Cumputer assembler to do the same as the C code below int main() { in
Little Man Cumputer assembly language code Q. Write the assembler program using Little Man Cumputer assembler to do the same as the C code below int main() { in
Little Man Cumputer assembly language code Q. Write the assembler program using Little Man Cumputer assembler to do the same as the C code below int main() { in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site