Answered step by step
Verified Expert Solution
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 _
Im getting a segmentation error for my code.
I run bit os pi
How to fix?
data
startingconfig: word @ starting configuration of piles
finalconfig: word @ final configuration of piles
text
global main
main:
bl randomizepiles
bl printpiles
bl solitaire
mov r #
mov r #
svc #
randomizepiles:
ldr rstartingconfig
ldr r
mov r #
mov r #
randomizepilesloop:
cmp r #
beq randomizepilesend @ if yes, end loop
bl rand
and r r #
add r r #
cmp r r
ble randomizepilesvalid
randomizepilesvalid:
str rr r lsl #
add r r #
sub r r r
b randomizepilesloop
randomizepilesend:
bx lr
printpiles:
ldr rstartingconfig
ldr r
mov r #
printpilesloop:
cmp r # @ check if all piles have been printed
beq printpilesend @ if yes, end loop
ldr rr r lsl # @ load pile size from starting configuration array
mov r r @ set pile number pile counter
add r r # @ increment pile number for printing based index
bl printint @ print pile number
mov r #
bl printchar @ print space
mov r #
bl printchar @ print
mov r r @ set pile size for printing
bl printint @ print pile size
mov r #
bl printchar @ print
mov r #
bl printchar @ print space
add r r # @ increment pile counter
sub r r # @ decrement number of piles to print
b printpilesloop @ repeat until all piles have been printed
printpilesend:
mov r #
bl printchar @ print newline
bx lr
solitaire:
ldr rstartingconfig @ load starting configuration address
ldr rfinalconfig @ load final configuration address
solitairemainloop:
bl solitairestep @ perform a solitaire step
bl solitairecheck @ check if final configuration is reached
cmp r #
beq solitaireend
b solitairemainloop @ repeat until final configuration is reached
solitaireend:
bl printpiles @ print final configuration of piles
bx lr
solitairestep:
ldr rstartingconfig @ load starting configuration address
mov r # @ initialize pile counter
solitairesteploop:
ldr rr r lsl # @ load pile size from starting configuration array
sub r r # @ remove one card from pile
str rr r lsl # @ store updated pile size in starting configuration array
add r r # @ increment pile counter
cmp r # @ check if we've gone through all piles
bne solitairesteploop @ repeat until all piles have been updated
ldr rr # @ get the size of the last pile address calculation:
add r r # @ add one card to the last pile
str rr # @ store updated pile size
bx lr
solitairecheck:
ldr rstartingconfig @ load starting configuration address
ldr rfinalconfig @ load final configuration address
mov r # @ initialize pile counter
solitairecheckloop:
ldr rr r lsl # @ load pile size from starting configuration array
ldr rr r lsl # @ load pile size from final configuration array
cmp r r @ compare starting configuration pile size to final configuration pile size
bne solitairecheckfail @ if not equal, exit loop
add r r # @ increment pile counter
cmp r # @ check if all piles have been checked
bne solitairecheckloop @ repeat until all piles have been checked
mov r # @ set result to indicate success
bx lr
solitairecheckfail:
mov r # @ set result to indicate failure
bx lr
printint:
@ Placeholder for integer printing function
bx lr
printchar:
@ 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started