Creating the assembly language file Before you start on this program, you might
ID: 3684853 • Letter: C
Question
Creating the assembly language file Before you start on this program, you might try modifying the Hello World program to print using the glibc functions. This assignment will examine three basic techniques: loops, testing and output. Modify the Hello World program to print the numbers 1 through 100, one per line. (I recommend getting this to work first.) Then follow the rules for the children's counting game Fizz: whenever the number is evenly divisible by 5, or contains the digit 5, replace the number by the wordExplanation / Answer
.LC0:
.string " Fizz"
.LC1:
.string " %d"
main:
stp x29, x30, [sp, -32]!
add x29, sp, 0
mov w0, 1
str w0, [x29,28]
b .L2
.L5:
ldr w1, [x29,28]
mov w0, 5
sdiv w2, w1, w0
mov w0, w2
lsl w0, w0, 2
add w0, w0, w2
sub w0, w1, w0
cmp w0, wzr
bne .L3
adrp x0, .LC0
add x0, x0, :lo12:.LC0
bl printf
b .L4
.L3:
adrp x0, .LC1
add x0, x0, :lo12:.LC1
ldr w1, [x29,28]
bl printf
.L4:
ldr w0, [x29,28]
add w0, w0, 1
str w0, [x29,28]
.L2:
ldr w0, [x29,28]
cmp w0, 100
ble .L5
mov w0, 0
ldp x29, x30, [sp], 32
ret
EQUIVALENT C CODE
---------------------------------------------------
#include<stdio.h>
main(){
int i;
for(i=1;i<=100;i++){
if(i%5 == 0){
printf(" Fizz");
}
else{
printf(" %d",i);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.