92 lines
2.3 KiB
ArmAsm
92 lines
2.3 KiB
ArmAsm
|
# Test for add64
|
||
|
|
||
|
.org 0
|
||
|
# Provide program starting address to linker
|
||
|
.global _start
|
||
|
|
||
|
.extern add64
|
||
|
.extern tohex
|
||
|
|
||
|
/* newlib system calls */
|
||
|
.set SYSEXIT, 93
|
||
|
.set SYSWRITE, 64
|
||
|
|
||
|
.section .rodata
|
||
|
|
||
|
inputs:
|
||
|
.word 0x40000000 # 0.25
|
||
|
.word 1 # 1
|
||
|
.word 0x40000000 # 0.25
|
||
|
.word 2 # 2
|
||
|
|
||
|
.word 0x40000000 # 0.25
|
||
|
.word 1 # 1
|
||
|
.word 0x80000000 # 0.5
|
||
|
.word 2 # 2
|
||
|
|
||
|
.set inputs_end, .-inputs
|
||
|
|
||
|
.section .bss
|
||
|
|
||
|
buf: .skip 9
|
||
|
|
||
|
.text
|
||
|
|
||
|
_start:
|
||
|
li a0, '\n
|
||
|
la a1, buf
|
||
|
sb a0, 8(a1) # append newline to buf
|
||
|
|
||
|
la s0, inputs # init loop variables
|
||
|
la s1, inputs_end
|
||
|
loop:
|
||
|
lw a0, 0(s0) # a0: x lower 32 bits
|
||
|
lw a1, 4(s0) # a1: x upper 32 bits
|
||
|
lw a2, 8(s0) # a2: y lower 32 bits
|
||
|
lw a3, 12(s0) # a3: y upper 32 bits
|
||
|
jal add64
|
||
|
|
||
|
# TODO: Format as an actual decimal
|
||
|
# print the result, hi = a1, lo = a0, a1.a0
|
||
|
# a0 is value, a1 is buf addr
|
||
|
addi sp, sp, -4
|
||
|
sw a0, 0(sp) # stash a0 for later
|
||
|
mv a0, a1 # copy a1 to a0
|
||
|
la a1, buf
|
||
|
jal tohex
|
||
|
|
||
|
# print hi word
|
||
|
li t0, SYSWRITE # "write" syscall
|
||
|
li a0, 1 # 1 = standard output (stdout)
|
||
|
la a1, buf # load address of output string
|
||
|
li a2, 8 # length of output string
|
||
|
ecall # invoke syscall to print the string
|
||
|
|
||
|
# print .
|
||
|
li t0, SYSWRITE # "write" syscall
|
||
|
li a0, 1 # 1 = standard output (stdout)
|
||
|
la a1, buf # load address of output string
|
||
|
li a2, '.
|
||
|
sb a2, 0(a1)
|
||
|
li a2, 1 # length of output string
|
||
|
ecall # invoke syscall to print the string
|
||
|
|
||
|
# print lo word
|
||
|
lw a0, 0(sp) # restore lo word
|
||
|
addi sp, sp, 4
|
||
|
la a1, buf
|
||
|
jal tohex
|
||
|
|
||
|
li t0, SYSWRITE # "write" syscall
|
||
|
li a0, 1 # 1 = standard output (stdout)
|
||
|
la a1, buf # load address of output string
|
||
|
li a2, 9 # length of output string
|
||
|
ecall # invoke syscall to print the string
|
||
|
|
||
|
addi s0, s0, 16 # increment input pointer to next pair of 64-bit inputs
|
||
|
bltu s0, s1, loop # if the input address is less than inputs_end, loop
|
||
|
|
||
|
li t0, SYSEXIT # "exit" syscall
|
||
|
la a0, 0 # Use 0 return code
|
||
|
ecall # invoke syscall to terminate the program
|