Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ' m getting a segmentation error for my code. I run 3 2 bit os pi 4 How to fix? . data starting _

I'm getting a segmentation error for my code.
I run 32bit os pi 4
How to fix?
.data
starting_config: .word 20,5,1,9,10 @ starting configuration of piles
final_config: .word 1,2,3,4,5,6,7,8,9 @ final configuration of piles
.text
.global main
main:
bl randomize_piles
bl print_piles
bl solitaire
mov r7, #1
mov r0, #0
svc #0
randomize_piles:
ldr r0,=starting_config
ldr r1,=45
mov r2, #0
mov r3, #0
randomize_piles_loop:
cmp r1, #0
beq randomize_piles_end @ if yes, end loop
bl rand
and r4, r0, #7
add r4, r4, #1
cmp r4, r1
ble randomize_piles_valid
randomize_piles_valid:
str r4,[r0, r2, lsl #2]
add r2, r2, #1
sub r1, r1, r4
b randomize_piles_loop
randomize_piles_end:
bx lr
print_piles:
ldr r0,=starting_config
ldr r1,=5
mov r2, #0
print_piles_loop:
cmp r1, #0 @ check if all piles have been printed
beq print_piles_end @ if yes, end loop
ldr r3,[r0, r2, lsl #2] @ load pile size from starting configuration array
mov r4, r2 @ set pile number (pile counter)
add r4, r4, #1 @ increment pile number for printing (1-based index)
bl print_int @ print pile number
mov r4, #32
bl print_char @ print space
mov r4, #91
bl print_char @ print '['
mov r4, r3 @ set pile size for printing
bl print_int @ print pile size
mov r4, #93
bl print_char @ print ']'
mov r4, #32
bl print_char @ print space
add r2, r2, #1 @ increment pile counter
sub r1, r1, #1 @ decrement number of piles to print
b print_piles_loop @ repeat until all piles have been printed
print_piles_end:
mov r4, #10
bl print_char @ print newline
bx lr
solitaire:
ldr r0,=starting_config @ load starting configuration address
ldr r1,=final_config @ load final configuration address
solitaire_main_loop:
bl solitaire_step @ perform a solitaire step
bl solitaire_check @ check if final configuration is reached
cmp r0, #1
beq solitaire_end
b solitaire_main_loop @ repeat until final configuration is reached
solitaire_end:
bl print_piles @ print final configuration of piles
bx lr
solitaire_step:
ldr r0,=starting_config @ load starting configuration address
mov r2, #0 @ initialize pile counter
solitaire_step_loop:
ldr r3,[r0, r2, lsl #2] @ load pile size from starting configuration array
sub r3, r3, #1 @ remove one card from pile
str r3,[r0, r2, lsl #2] @ store updated pile size in starting configuration array
add r2, r2, #1 @ increment pile counter
cmp r2, #9 @ check if we've gone through all piles
bne solitaire_step_loop @ repeat until all piles have been updated
ldr r3,[r0, #(8*4)] @ get the size of the last pile (address calculation: 8*4)
add r3, r3, #1 @ add one card to the last pile
str r3,[r0, #(8*4)] @ store updated pile size
bx lr
solitaire_check:
ldr r0,=starting_config @ load starting configuration address
ldr r1,=final_config @ load final configuration address
mov r2, #0 @ initialize pile counter
solitaire_check_loop:
ldr r3,[r0, r2, lsl #2] @ load pile size from starting configuration array
ldr r4,[r1, r2, lsl #2] @ load pile size from final configuration array
cmp r3, r4 @ compare starting configuration pile size to final configuration pile size
bne solitaire_check_fail @ if not equal, exit loop
add r2, r2, #1 @ increment pile counter
cmp r2, #9 @ check if all piles have been checked
bne solitaire_check_loop @ repeat until all piles have been checked
mov r0, #1 @ set result to indicate success
bx lr
solitaire_check_fail:
mov r0, #0 @ set result to indicate failure
bx lr
print_int:
@ Placeholder for integer printing function
bx lr
print_char:
@ Placeholder for character printing function
bx lr
rand:
@ Placeholder for random number generation function
bx lr

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

Students also viewed these Databases questions

Question

=+1. Who is responsible for CSRfirms or their stakeholders? Why?

Answered: 1 week ago