Write an assembly language program to do the following, and run it and test it o
ID: 3917242 • Letter: W
Question
Write an assembly language program to do the following, and run it and
test it on the lab simulator:
Read in integers until a zero is read in. Keep a total of both the quantity and the sum
of the negative integers and the positive integers. Once a zero is read in (signifying
the end of the input) then:
• If there were more positive than negative integers, or an equal number, print
out a 0 and the sum of the positive integers.
• If there were more negative than positive integers, print out a 1 and the sum
of the negative integers.
Hand in your answer to this question as
1. A screen shot of the lab assembler program once your program has been
assembled successfully, showing that it assembled successfully.
2. A complete separate print-out of your source code with comments, as it may not
all be visible in the assembler simulator window.
3. Screen shots of the von Neumann assembler execution window after execution of
your program executed with some sample data, for both situations (more negative
integers, and more positive integers).
4. The sample data you used to test the program in both situations.
Explanation / Answer
Here is the code for the given problem in Assembly Language>
Please comment below for any queries i will help you with that. Thank you.
Assembly Program
.LC0:
.string "%d"
.LC1:
.string "0 and sum of positive integers are:%d"
.LC2:
.string "1 and sum of negative integers are:%d"
main:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movl $0, -20(%rbp)
movl $0, -4(%rbp)
movl $0, -8(%rbp)
movl $0, -12(%rbp)
movl $0, -16(%rbp)
.L4:
leaq -20(%rbp), %rax
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
call __isoc99_scanf
movl -20(%rbp), %eax
testl %eax, %eax
jle .L2
addl $1, -4(%rbp)
movl -20(%rbp), %eax
addl %eax, -12(%rbp)
jmp .L3
.L2:
addl $1, -8(%rbp)
movl -20(%rbp), %eax
addl %eax, -16(%rbp)
.L3:
movl -20(%rbp), %eax
testl %eax, %eax
jne .L4
movl -4(%rbp), %eax
cmpl -8(%rbp), %eax
jl .L5
movl -12(%rbp), %eax
movl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
jmp .L6
.L5:
movl -16(%rbp), %eax
movl %eax, %esi
movl $.LC2, %edi
movl $0, %eax
call printf
.L6:
movl $0, %eax
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.