Skip to content

Commit

Permalink
Print register works.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rusty Mellinger committed Jul 8, 2013
1 parent 6330edf commit 6e35129
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 66 deletions.
124 changes: 71 additions & 53 deletions swi-util.S
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
.global log
/* Address of string to log in R1. */
log:
mov x29, x30
mov w4, w1
# Address of string to log is in R1.
mov x29, x30
mov w25, w1

#ldr x1, =elap
#mov w0, #0x30 /* SWI: elapsed */
#hlt #0xf000 /* R1 = &elap */
ldr x1, =elap
mov w0, #0x30 /* elapsed instructions */
hlt #0xf000

mov w6, #140
bl print_byte
ldr x7, =testdata
ldr w6, [x7]
bl print_quad
ldr w6, [x7, #4]
bl print_quad

ret x29

print_byte:
mov x28, x30
asr w1, w6, #4 /* Top four bits. */
bl print_nibble
and w1, w6, #15 /* Bottom four bits. */
bl print_nibble
ret x28

print_nibble:
# R1 is a nibble.
ldr x4, =hbyte
add w2, w1, #0x30 /* R2 = '0' + w1 */
add w3, w1, #0x57 /* R3 = 'a' + w1 - 10 */
cmp x1, #9
csel w1, w2, w3, ls
strb w1, [x4]
mov x1, x4
mov w0, #0x03
hlt #0xf000
ret
# Print the string
mov x1, x25
mov w0, #0x04
hlt #0xf000


hex_byte:
ldr b6, [x6]
ldr x8, =hbyte
ret x29

asr w1, w6, #4 /* Top four bits. */
add w5, w1, #0x30 /* R5 = '0' + w1 */
add w7, w1, #0x61 /* R7 = 'a' + w1 */
cmp w1, #9
csel w1, w5, w7, mi
.global print_quad
print_quad:
# [0 1 2 3 4 6 26 27 28 30]
mov x27, x30
rev w6, w6
mov w26, #0
pq_loop:
bl print_byte
add w26, w26, #1
cmp w26, #4
asr w6, w6, #8
blt pq_loop
ldr x1, =hbyte
mov x2, #0x7c
strb w2, [x1]
mov x0, #0x03
hlt #0xf000
ret x27

strb w1, [x8]
mov x1, x8
mov w0, #0x03
hlt #0xf000
print_r5:
mov x24, x30
ret x24

and x1, x6, #15
cmp w1, #9
csel w1, w5, w7, mi
strb w1, [x8]
mov x1, x8
mov w0, #0x03
hlt #0xf000
print_byte:
# R6 is a byte.
# [0 1 2 3 4 6 28 30]
mov x28, x30
asr w1, w6, #4 /* Top four bits. */
and w1, w1, #0x0000000f
bl print_nibble
and w1, w6, #0x0000000f /* Bottom four bits. */
bl print_nibble
ret x28

ret
print_nibble:
# R1 is a nibble.
# [0 1 2 3 4 30]
ldr x4, =hbyte
add w2, w1, #0x30 /* R2 = '0' + w1 */
add w3, w1, #0x57 /* R3 = 'a' + w1 - 10 */
cmp x1, #9
csel w1, w2, w3, ls
strb w1, [x4]
mov x1, x4
mov w0, #0x03
hlt #0xf000
ret

elap:
.word 0x00000000
.word 0x00000000
.word 0x00000000
.word 0x00000000

hbyte:
.byte 0x00
.byte 0x00

.align 8
testdata:
.word 0x01234567
.word 0xdeadbeef

newline:
.byte '\n'
30 changes: 17 additions & 13 deletions test-util.S
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
.section .text, "ax"

.global _start
_start:
# Attempt to initialize the stack?
#adr x1, stack_addr
#ldr x1, [x1]
#mov sp, x1
bl init_stack

test: ldr x1, =hello
bl log

ldr w1, =hello
bl log
movz w0, #0x18 /* SWI: Exit */
hlt #0xf000
b . /* Infinite loop */
exit: movz w0, #0x18 /* Exit */
hlt #0xf000
b .

hello:
.ascii "\nHello, world!\n"
init_stack:
adr x29, stack
ldr x29, [x29]
mov sp, x29
ret

stack_addr:
.quad 0x0000000088000000
hello: .ascii "Hello, world!\n\0"

.align 2
stack: .quad 0x0000000088000000

0 comments on commit 6e35129

Please sign in to comment.