Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly program called hw5_ex1 , stored in file hw5_ex1.asm . This pro

ID: 3532821 • Letter: W

Question

Write an assembly program called hw5_ex1, stored in file hw5_ex1.asm. This program should prompt the user to enter 10 numbers between 0 and 9 (both included). The program should print an error message and re-prompt the user for another number if the number entered is invalid. These numbers should be stored in memory as 1-byte values. Once the user has entered 10 valid numbers, the program should just print them out in the order they were entered.

Here is an example interaction with the program (note that in the end only the 10 valid entered numbers are taken into account):

% ./hw5_ex1
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: 12
Invalid number!
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 0
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: -12
Invalid number!
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 4
Enter a number between 0 and 9: 5
Enter a number between 0 and 9: 1
2
3
1
0
2
2
3
4
5
1

Explanation / Answer

I've prefixed all lines that begin with a tab with a +: initial white space on the lien will be filtered out.

+.section ".rodata"
+.align 8
.LLC0:
+.asciz "Enter a number between 0 and 9: "
+.align 8
.LLC1:
+.asciz "%d"
+.align 8
.LLC2:
+.asciz "Invalid number!"
+.align 8
.LLC3:
+.asciz "%d "
+.section ".text"
+.align 4
+.global main
+.type main, #function
+.proc 04
main:
+save %sp, -152, %sp
+st %g0, [%fp-12]
+b .LL2
+ nop
.LL3:
+sethi %hi(.LLC0), %g1
+or %g1, %lo(.LLC0), %o0
+call printf, 0
+ nop
+ld [%fp-12], %g1
+sll %g1, 2, %g1
+mov %g1, %g2
+add %fp, -52, %g1
+add %g1, %g2, %g1
+sethi %hi(.LLC1), %g2
+or %g2, %lo(.LLC1), %o0
+mov %g1, %o1
+call scanf, 0
+ nop
+ld [%fp-12], %g1
+sll %g1, 2, %g2
+add %fp, -8, %g1
+add %g2, %g1, %g1
+ld [%g1-44], %g1
+cmp %g1, 0
+bl .LL4
+ nop
+ld [%fp-12], %g1
+sll %g1, 2, %g2
+add %fp, -8, %g1
+add %g2, %g1, %g1
+ld [%g1-44], %g1
+cmp %g1, 9
+ble .LL6
+ nop
.LL4:
+sethi %hi(.LLC2), %g1
+or %g1, %lo(.LLC2), %o0
+call puts, 0
+ nop
+ld [%fp-12], %g1
+add %g1, -1, %g1
+st %g1, [%fp-12]
.LL6:
+ld [%fp-12], %g1
+add %g1, 1, %g1
+st %g1, [%fp-12]
.LL2:
+ld [%fp-12], %g1
+cmp %g1, 9
+ble .LL3
+ nop
+st %g0, [%fp-12]
+b .LL8
+ nop
.LL9:
+ld [%fp-12], %g1
+sll %g1, 2, %g2
+add %fp, -8, %g1
+add %g2, %g1, %g1
+ld [%g1-44], %g2
+sethi %hi(.LLC3), %g1
+or %g1, %lo(.LLC3), %o0
+mov %g2, %o1
+call printf, 0
+ nop
+ld [%fp-12], %g1
+add %g1, 1, %g1
+st %g1, [%fp-12]
.LL8:
+ld [%fp-12], %g1
+cmp %g1, 9
+ble .LL9
+ nop
+restore
+jmp %o7+8
+ nop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote