Assembly Program that will: Load program at x3000 Prompt for Number (1 – 9) Outp
ID: 3740401 • Letter: A
Question
Assembly Program that will:
Load program at x3000
Prompt for Number (1 – 9)
Output: negative of that number
Example:
Please input a number from 1 – 9:
>> 5 (User inputs a 5)
Negative value: -5
this needs to be written in lc3
; coRY WINDHAM 2810-001
; THIS PROGRAM PROMPTS USER FR NUMBER 1-9 THEN FLIPS THAT INPUT NEGATIVE
.ORIG X3000
; intro string and instructions
LEA R0, INTRO1
PUTS
LEA R0, INTRO2
PUTS
; get user input
IN ; get user input
;output value
LEA R0, OUTPUT
PUTS
HALT
INTRO1 .STRINGZ "THIS PROGRAM TAKES YOUR NUMBER AND MAKES IT NEGATOVE. "
INTRO2 .STRINGZ "PLEASE ENTER A NUMBER BETWEEN 1 AND 9. "
OUTPUT .STRINGZ "NEGATIVE VALUE"
.END
this is what I have
Explanation / Answer
Answer:
Assembly Language Code :
.LC6:
.string "%f"
main:
push rbp
mov rbp, rsp
sub rsp, 64
movsd xmm0, QWORD PTR .LC0[rip]
movsd QWORD PTR [rbp-48], xmm0
movsd xmm0, QWORD PTR .LC1[rip]
movsd QWORD PTR [rbp-40], xmm0
movsd xmm0, QWORD PTR .LC2[rip]
movsd QWORD PTR [rbp-32], xmm0
movsd xmm0, QWORD PTR .LC3[rip]
movsd QWORD PTR [rbp-24], xmm0
pxor xmm0, xmm0
movsd QWORD PTR [rbp-8], xmm0
mov DWORD PTR [rbp-12], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-12]
cdqe
movsd xmm1, QWORD PTR [rbp-48+rax*8]
movq xmm0, QWORD PTR .LC5[rip]
andpd xmm0, xmm1
movsd xmm1, QWORD PTR [rbp-8]
addsd xmm0, xmm1
movsd QWORD PTR [rbp-8], xmm0
add DWORD PTR [rbp-12], 1
.L2:
cmp DWORD PTR [rbp-12], 3
jle .L3
mov rax, QWORD PTR [rbp-8]
mov QWORD PTR [rbp-56], rax
movsd xmm0, QWORD PTR [rbp-56]
mov edi, OFFSET FLAT:.LC6
mov eax, 1
call printf
mov eax, 0
leave
ret
.LC0:
.long 0
.long -1074790400
.LC1:
.long 0
.long 1073741824
.LC2:
.long 0
.long 1074790400
.LC3:
.long 0
.long -1072168960
.LC5:
.long 4294967295
.long 2147483647
.long 0
.long 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.