Created
December 21, 2011 23:25
-
-
Save dockimbel/1508186 to your computer and use it in GitHub Desktop.
Not working abs(x) routine for x = -2^31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Division routine | |
93c4: e3510000 cmp r1, #0 | |
93c8: 0a000014 beq 0x9420 | |
93cc: e1b02001 movs r2, r1 ; r2: divisor | |
93d0: e212c102 ands ip, r2, #-2147483648 ; 0x80000000 | |
93d4: 40225fc2 eormi r5, r2, r2, asr #31 | |
93d8: 40452fc2 submi r2, r5, r2, asr #31 | |
93dc: e1b01000 movs r1, r0 ; r1: dividend | |
93e0: e03cc041 eors ip, ip, r1, asr #32 | |
93e4: 40215fc1 eormi r5, r1, r1, asr #31 | |
93e8: 40451fc1 submi r1, r5, r1, asr #31 | |
93ec: e3a00000 mov r0, #0 | |
93f0: e3a03001 mov r3, #1 | |
93f4: e1520001 cmp r2, r1 | |
93f8: 91a02082 lslls r2, r2, #1 | |
93fc: 91a03083 lslls r3, r3, #1 | |
9400: 9afffffb bls 0x93f4 | |
9404: e1510002 cmp r1, r2 | |
9408: 20411002 subcs r1, r1, r2 | |
940c: 20800003 addcs r0, r0, r3 | |
9410: e1b030a3 lsrs r3, r3, #1 | |
9414: 31a020a2 lsrcc r2, r2, #1 | |
9418: 3afffff9 bcc 0x9404 | |
941c: e1b0c08c lsls ip, ip, #1 | |
9420: 22600000 rsbcs r0, r0, #0 | |
9424: 42611000 rsbmi r1, r1, #0 | |
9428: e3340000 teq r4, #0 | |
942c: 01a0f00e moveq pc, lr | |
9430: e1b00001 movs r0, r1 | |
9434: e3340002 teq r4, #2 | |
9438: 01a0f00e moveq pc, lr | |
943c: e3500000 cmp r0, #0 | |
9440: 51a0f00e movpl pc, lr | |
9444: e3520000 cmp r2, #0 | |
9448: 41e00000 mvnmi r0, r0 | |
944c: e0800002 add r0, r0, r2 | |
9450: e1a0f00e mov pc, lr | |
; Debugging session | |
(gdb) br *0x93e0 | |
Breakpoint 1 at 0x93e0 | |
(gdb) r | |
Starting program: /root/ARM/test-division | |
Breakpoint 1, 0x000093e0 in ?? () | |
(gdb) i r | |
r0 0x80000000 2147483648 | |
r1 0x80000000 2147483648 | |
r2 0x10000 65536 | |
r3 0x0 0 | |
r4 0x0 0 | |
r5 0x0 0 | |
r6 0x81a4 33188 | |
r7 0x0 0 | |
r8 0x0 0 | |
r9 0x0 0 | |
r10 0x40025000 1073893376 | |
r11 0x0 0 | |
r12 0x0 0 | |
sp 0xbea27d84 0xbea27d84 | |
lr 0x848c 33932 | |
pc 0x93e0 0x93e0 | |
cpsr 0xa0000010 -1610612720 | |
(gdb) display/i $pc | |
1: x/i $pc | |
Disabling display 1 to avoid infinite recursion. | |
Cannot access memory at address 0x0 | |
=> 0x93e0: eors r12, r12, r1, asr #32 | |
(gdb) si | |
Cannot access memory at address 0x0 | |
Cannot access memory at address 0x0 | |
0x000093e4 in ?? () | |
(gdb) i r | |
r0 0x80000000 2147483648 | |
r1 0x80000000 2147483648 | |
r2 0x10000 65536 | |
r3 0x0 0 | |
r4 0x0 0 | |
r5 0x0 0 | |
r6 0x81a4 33188 | |
r7 0x0 0 | |
r8 0x0 0 | |
r9 0x0 0 | |
r10 0x40025000 1073893376 | |
r11 0x0 0 | |
r12 0xffffffff 4294967295 | |
sp 0xbea27d84 0xbea27d84 | |
lr 0x848c 33932 | |
pc 0x93e4 0x93e4 | |
cpsr 0xa0000010 -1610612720 | |
(gdb) si | |
Cannot access memory at address 0x0 | |
Cannot access memory at address 0x0 | |
0x000093e8 in ?? () | |
(gdb) i r | |
r0 0x80000000 2147483648 | |
r1 0x80000000 2147483648 | |
r2 0x10000 65536 | |
r3 0x0 0 | |
r4 0x0 0 | |
r5 0x7fffffff 2147483647 | |
r6 0x81a4 33188 | |
r7 0x0 0 | |
r8 0x0 0 | |
r9 0x0 0 | |
r10 0x40025000 1073893376 | |
r11 0x0 0 | |
r12 0xffffffff 4294967295 | |
sp 0xbea27d84 0xbea27d84 | |
lr 0x848c 33932 | |
pc 0x93e8 0x93e8 | |
cpsr 0xa0000010 -1610612720 | |
(gdb) display/i $pc | |
2: x/i $pc | |
=> 0x93e8: submi r1, r5, r1, asr #31 | |
(gdb) si | |
Cannot access memory at address 0x0 | |
Cannot access memory at address 0x0 | |
0x000093ec in ?? () | |
2: x/i $pc | |
=> 0x93ec: mov r0, #0 | |
(gdb) i r | |
r0 0x80000000 2147483648 | |
r1 0x80000000 2147483648 | |
r2 0x10000 65536 | |
r3 0x0 0 | |
r4 0x0 0 | |
r5 0x7fffffff 2147483647 | |
r6 0x81a4 33188 | |
r7 0x0 0 | |
r8 0x0 0 | |
r9 0x0 0 | |
r10 0x40025000 1073893376 | |
r11 0x0 0 | |
r12 0xffffffff 4294967295 | |
sp 0xbea27d84 0xbea27d84 | |
lr 0x848c 33932 | |
pc 0x93ec 0x93ec | |
cpsr 0xa0000010 -1610612720 | |
(gdb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment