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 0
width: .word 0
.text
// Function to get the rectangle's length
getLength:
push {lr}
ldr r0,=promptLength // Load prompt for length
bl printf // Print the prompt
ldr r0,=inputFormat
ldr r1,=length // Use the address of `length`
bl scanf // Get user input for length
ldr r0,[r1]// Load length from memory into r0
pop {pc}// Return with length in r0
// Function to get the rectangle's width
getWidth:
push {lr}
ldr r0,=promptWidth // Load prompt for width
bl printf // Print the prompt
ldr r0,=inputFormat
ldr r1,=width // Use the address of `width`
bl scanf // Get user input for width
ldr r0,[r1]// Load width from memory into r0
pop {pc}// Return with width in r0
// Function to calculate the rectangle's area
getArea:
push {lr}
mul r0, r0, r1// r0= r0* r1(length * width)
pop {pc}// Return with area in r0
// Function to display the rectangle's data
displayData:
push {lr}
ldr r0,=outputArea // Load output format string
mov r1, r2// Move length to r1
mov r2, r3// Move width to r2
mov r3, r4// Move area to r3
bl printf // Print formatted output
pop {pc}
// Main function to coordinate the flow
main:
push {lr}
// Get length
bl getLength // Call getLength
mov r2, r0// Store length in r2
// Get width
bl getWidth // Call getWidth
mov r3, r0// Store width in r3
// Calculate area
mov r0, r2// Move length to r0 for getArea
mov r1, r3// Move width to r1 for getArea
bl getArea // Calculate area
mov r4, r0// Store area in r4
// Display the result
bl displayData // Show length, width, and area
mov r0, #0// Exit code 0
pop {pc}
1. 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:
- getLength-This function should ask the user to enter the rectangle's length then return that value.
- getWidth-This function should ask the user to enter the rectangle's width then return that value.
- getArea-This 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.
- displayData-This function should accept the rectangle's length, width, and area as arguments and display them in an appropriate message on the screen.
help with my Assembly code , it not working , cuz

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!