Question: help with my Assembly code , it not working , cuz of Segmention fault . global main . global getLength . global getWidth . global
help with my Assembly code it not working cuz of Segmention fault
global main
global getLength
global getWidth
global getArea
global displayData
section rodata
promptLength: asciz "Enter the rectangle's length:
promptWidth: asciz "Enter the rectangle's width:
outputArea: asciz "The rectangle with length d and width d has an area of d
inputFormat: asciz d
section data
length: word
width: word
text
Function to get the rectangle's length
getLength:
push lr
ldr rpromptLength Load prompt for length
bl printf Print the prompt
ldr rinputFormat
ldr rlength Use the address of length
bl scanf Get user input for length
ldr rr Load length from memory into r
pop pc Return with length in r
Function to get the rectangle's width
getWidth:
push lr
ldr rpromptWidth Load prompt for width
bl printf Print the prompt
ldr rinputFormat
ldr rwidth Use the address of width
bl scanf Get user input for width
ldr rr Load width from memory into r
pop pc Return with width in r
Function to calculate the rectangle's area
getArea:
push lr
mul r r r r r rlength width
pop pc Return with area in r
Function to display the rectangle's data
displayData:
push lr
ldr routputArea Load output format string
mov r r Move length to r
mov r r Move width to r
mov r r Move area to r
bl printf Print formatted output
pop pc
Main function to coordinate the flow
main:
push lr
Get length
bl getLength Call getLength
mov r r Store length in r
Get width
bl getWidth Call getWidth
mov r r Store width in r
Calculate area
mov r r Move length to r for getArea
mov r r Move width to r for getArea
bl getArea Calculate area
mov r r Store area in r
Display the result
bl displayData Show length, width, and area
mov r # Exit code
pop pc
Rectangle Area
The program will ask the user to enter the width and length of a rectangle, then display the rectangle's area. The program calls the following functions, which have not been written:
getLengthThis function should ask the user to enter the rectangle's length then return that value.
getWidthThis function should ask the user to enter the rectangle's width then return that value.
getAreaThis function should accept the rectangle's length and width as arguments and return the rectangle's area. The area is calculated by multiplying the length by the width.
displayDataThis function should accept the rectangle's length, width, and area as arguments and display them in an appropriate message on the screen.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
