7. Write a Hmmm assembly-language program that gets two positive integers from t
ID: 3738773 • Letter: 7
Question
7. Write a Hmmm assembly-language program that gets two positive integers from the user, subtracts the second integer from the first,and writes out the square of the result. 8. Write a Hmmm assembly-language program that uses a loop that allows the user to enter one or more integers. When the user enters a zero, the program should stop looping and write out two counts: how many of the numbers were positive, and how many were negative. Don't count the zero. 9. Write a Hmmm assembly language program that takes in a positive integer as input and calls a separate function that many times. The function should simply write out the number 111. You must use call and jumpr instructions to implement your function.Explanation / Answer
1)
0 read r1
1 read r2
2 sub r1, r1, r2
3 mul r1, r1, r1
4 write r1
2)
0 setn r2, 0 ; number of positive numbers
1 setn r3, 0 ; number of negative numbers
2 read r1 ; Read number
3 jeqzn r1, 9 ; if r1 == 0 end loop
4 jltzn r1, 7 ; if r1<0, increment count of negative words
5 add r2, 1
6 jumpn 2
7 add r3, 1
8 jumpn 2
9 write r2
10 write r3
3)
0 read r1 ; read number
1 copy r2, r1 ; loop counter
2 jeqzn r1, 9 ; if loop counter reaches 0, end the function
3 calln r3, 6
4 sub r2, 1 ; decremment loop counter
5 jumpn 2
6 setn r4, 111
7 write r4
8 jumpn 4
9 halt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.