I have a very simple problem but it is driving me up the wall, would you please help me?
Here is the question: how do I compare two signed byte values in ARM assembly? This is what I tried:
ldrsb r1, [r0], #1
ldrsb r2, [r0]
cmp r1, r2
r0 is loaded with the address of a list of byte values like 10, -1, 123. should ldrsb not sig extend when loading a negative number? I am lost
EDIT:
well we're supposed to write a program that sorts of a list of signed byte values (using bubblesort). I can figure out how to do that, it's just that I don't understand the actual comparison (or its result). This is my code so far:
.global main
.section .data
myNumbers: .byte 183, 374, -113, -1, 10, 101, -3, -54, 9, 7
myNumbersEnd:
.section .text
main:
loop:
mov r4, #0
ldr r0, =myNumbers
ldr r3, =myNumbersEnd
inner_loop:
ldrsb r1, [r0], #1
ldrsb r2, [r0]
cmp r1, r2
strgtb r1, [r0]
strgtb r2, [r0, #-1]
movgt r4, #1 @ r4 = swapped = true
cmp r0, r3
bne inner_loop
cmp r4, #1
beq loop @ keep going
exit:
b exit
.end
Maybe I should add that i am not running this code on actual ARM hardware, but on ARMSim#, a simulator for the ARM7TDMI processor: http://armsim.cs.uvic.ca/index.html