In: Computer Science
Write a program named subtract.asm that does the following using LC3 assembly language:
Print a prompt "PRESS TWO KEYS: " Note that the prompt MUST LOOK EXACTLY like the above, with a colon and a space after the word KEYS with no newline. Get a two key press from the user. Subtract the second characters ASCII code from the first characters ASCII code. If the result is positive, print the word POSITIVE. Turn in subtract.asm to the appropriate submission point on Web-CAT.
HERE is the CODE:
.LC0:
.string "PRESS TWO KEYS: "
.LC1:
.string "%c%c"
.LC2:
.string "POSITIVE"
.LC3:
.string "NEGATIVE"
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rdx, [rbp-2]
lea rax, [rbp-1]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call __isoc99_scanf
movzx eax, BYTE PTR [rbp-1]
movsx edx, al
movzx eax, BYTE PTR [rbp-2]
movsx eax, al
sub edx, eax
mov eax, edx
test eax, eax
jle .L2
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L4
.L2:
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
.L4:
nop
leave
ret
SCREENSHOT: