Arm assembly language/Raspberry PI area/perimeter of rectangle calculator \"Writ
ID: 3691519 • Letter: A
Question
Arm assembly language/Raspberry PI area/perimeter of rectangle calculator "Write an ARM assembly language program for the Raspberry Pi that calculates and displays the perimeter or the area of a rectangle, given the length of each side, depending on the user’s input. The user should be prompted to enter the length of each of the sides; once these values have been read by the program, provide the user with the options to select which calculation to perform on the rectangle, and prompt them to enter one of the options. For example: Enter Perimeter(P) or Area(A)"Explanation / Answer
.rodata
prompt1: .string "Please enter the rectangle's length: "
prompt2: .string "Please enter the rectangle's width: "
perimeter: .string "The perimeter of the rectangle is %d. "
area: .string "The area of the rectangle is %d. "
scanf_int: .string "%d"
.bss
.align 4
length .int 0
.type length,@object
width .int 0
.type width,@object
pushl $prompt1
call printf
add $4,%esp #We pushed a 4-byte value, clean the stack up!
pushl $length
pushl $scanf_int
call scanf
addl $8,%esp #we pushed 2 4-byte values, clen the stack up!
.type f1,@function
.globl f1
f1:
pushl %ebp
movl %esp,%ebp
pushl $prompt1
call printf
add $4,%esp
pushl $length
pushl $scanf_int
call scanf
add $8,%esp
pushl $prompt2
call printf
addl $4,%esp
pushl $width
pushl $scanf_int
call scanf
addl $8,%esp
movl length,%eax #grab the stored value for the length
addl width,%eax #add the stored value for the width (length+width)
addl %eax,%eax #double it (2*(length+width))
movl %eax,f1_perimeter
movl length,%eax #grab the length again
mull width,%eax #multiply by the width
movl %eax,f1_area
pushl f1_perimeter #get the value and push it onto the stack
pushl $perimeter #push the pointer to the string
call printf
add $8,%esp
pushl f1_area #get the value and push it
pushl $area #...and the string for area
call printf
add $8,%esp
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.