Compare commits
No commits in common. "57c787f87dc7897f4f8dd50b700cff1f47db157e" and "86de75098ab82920c57cd718f980a1818cd2d8f0" have entirely different histories.
57c787f87d
...
86de75098a
52
lab1_v2.S
52
lab1_v2.S
|
@ -2,50 +2,26 @@
|
||||||
.cpu cortex-m4
|
.cpu cortex-m4
|
||||||
.thumb
|
.thumb
|
||||||
|
|
||||||
.macro BKPT_WRITE addr_src
|
.section .data
|
||||||
mov r1, \addr_src
|
test_string: .asciz "Hello"
|
||||||
mov r0, 0x4
|
|
||||||
bkpt 0xAB
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.section .text
|
.section .text
|
||||||
|
|
||||||
lab1_v2:
|
lab1_v2:
|
||||||
push.n {lr}
|
sub sp, #6
|
||||||
|
ldr r0, =test_string
|
||||||
|
mov r1, #5
|
||||||
|
|
||||||
mov r0, #2073
|
copy_loop:
|
||||||
bl int_to_str
|
ldrb r2, [r0, r1]
|
||||||
|
strb r2, [sp, r1]
|
||||||
|
subs r1, #1
|
||||||
|
bpl copy_loop
|
||||||
|
|
||||||
pop.n {pc}
|
mov r1, sp
|
||||||
|
mov r0, 0x04
|
||||||
|
bkpt 0xAB
|
||||||
|
|
||||||
int_to_str:
|
add sp, #6
|
||||||
mov r3, sp
|
|
||||||
|
|
||||||
@ write newline + NULL terminator
|
|
||||||
mov r5, #0x000A
|
|
||||||
strh r5, [r3, #-2]!
|
|
||||||
|
|
||||||
@ --- handmade modulo ---
|
|
||||||
mov r4, #10
|
|
||||||
|
|
||||||
iterate:
|
|
||||||
mov r1, r0 @ save orig to r1
|
|
||||||
udiv r0, r0, r4 @ orig/10 and overwrite old orig value
|
|
||||||
mul r2, r0, r4 @ orig/10*10, place separately
|
|
||||||
subs r5, r1, r2 @ orig - orig/10*10 => modulo (and update flags)
|
|
||||||
|
|
||||||
beq check_if_pending_digits_exist
|
|
||||||
proceed_with_conversion:
|
|
||||||
|
|
||||||
add r5, #48 @ int -> char (only digits, so it's fine)
|
|
||||||
strb r5, [r3, #-1]! @ write next char to RAM
|
|
||||||
b iterate
|
|
||||||
|
|
||||||
check_if_pending_digits_exist:
|
|
||||||
cmp r0, #0
|
|
||||||
bne proceed_with_conversion
|
|
||||||
|
|
||||||
finish:
|
|
||||||
BKPT_WRITE r3
|
|
||||||
|
|
||||||
mov pc, lr
|
mov pc, lr
|
||||||
|
|
Loading…
Reference in New Issue