sysy-data/functional_c/asm/69_expr_eval.s

641 lines
8.8 KiB
ArmAsm
Raw Normal View History

2024-06-14 13:10:27 +08:00
.file "69_expr_eval.sy"
.option pic
.attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0"
.attribute unaligned_access, 0
.attribute stack_align, 16
.text
.align 1
.globl next_char
.type next_char, @function
next_char:
addi sp,sp,-16
sd ra,8(sp)
call getch@plt
ld ra,8(sp)
sw a0,.LANCHOR0,a4
addi sp,sp,16
jr ra
.size next_char, .-next_char
.align 1
.globl is_space
.type is_space, @function
is_space:
li a5,32
beq a0,a5,.L6
addi a0,a0,-10
seqz a0,a0
ret
.L6:
li a0,1
ret
.size is_space, .-is_space
.align 1
.globl is_num
.type is_num, @function
is_num:
addiw a0,a0,-48
sltiu a0,a0,10
ret
.size is_num, .-is_num
.align 1
.globl next_token
.type next_token, @function
next_token:
addi sp,sp,-32
sd s0,16(sp)
lla s0,.LANCHOR0
lw a0,0(s0)
sd s1,8(sp)
sd s2,0(sp)
sd ra,24(sp)
li s1,32
li s2,10
.L9:
beq a0,s1,.L10
beq a0,s2,.L10
addiw a5,a0,-48
li a4,9
lla s1,.LANCHOR1
bleu a5,a4,.L11
sw a0,0(s1)
call getch@plt
sw a0,0(s0)
ld ra,24(sp)
ld s0,16(sp)
li a0,1
sw a0,8(s1)
ld s2,0(sp)
ld s1,8(sp)
addi sp,sp,32
jr ra
.L10:
call getch@plt
sw a0,0(s0)
j .L9
.L11:
sw a5,4(s1)
call getch@plt
li s2,9
sw a0,0(s0)
addiw a5,a0,-48
bgtu a5,s2,.L14
.L16:
lw a4,4(s1)
slliw a5,a4,2
addw a5,a5,a4
slliw a5,a5,1
addw a5,a5,a0
addiw a5,a5,-48
sw a5,4(s1)
call getch@plt
sw a0,0(s0)
addiw a5,a0,-48
bleu a5,s2,.L16
.L14:
ld ra,24(sp)
ld s0,16(sp)
li a0,0
sw a0,8(s1)
ld s2,0(sp)
ld s1,8(sp)
addi sp,sp,32
jr ra
.size next_token, .-next_token
.align 1
.globl panic
.type panic, @function
panic:
addi sp,sp,-16
li a0,112
sd ra,8(sp)
call putch@plt
li a0,97
call putch@plt
li a0,110
call putch@plt
li a0,105
call putch@plt
li a0,99
call putch@plt
li a0,33
call putch@plt
li a0,10
call putch@plt
ld ra,8(sp)
li a0,-1
addi sp,sp,16
jr ra
.size panic, .-panic
.align 1
.globl get_op_prec
.type get_op_prec, @function
get_op_prec:
addiw a0,a0,-37
li a5,10
bgtu a0,a5,.L21
li a5,1
sll a5,a5,a0
andi a4,a5,1057
li a0,20
bne a4,zero,.L20
andi a0,a5,320
snez a0,a0
neg a0,a0
andi a0,a0,10
ret
.L21:
li a0,0
.L20:
ret
.size get_op_prec, .-get_op_prec
.align 1
.globl stack_push
.type stack_push, @function
stack_push:
lw a5,0(a0)
addiw a4,a5,1
mv a5,a4
slli a4,a4,2
sw a5,0(a0)
add a0,a0,a4
sw a1,0(a0)
ret
.size stack_push, .-stack_push
.align 1
.globl stack_pop
.type stack_pop, @function
stack_pop:
lw a4,0(a0)
mv a5,a0
slli a3,a4,2
add a3,a0,a3
addiw a4,a4,-1
lw a0,0(a3)
sw a4,0(a5)
ret
.size stack_pop, .-stack_pop
.align 1
.globl stack_peek
.type stack_peek, @function
stack_peek:
lw a5,0(a0)
slli a5,a5,2
add a0,a0,a5
lw a0,0(a0)
ret
.size stack_peek, .-stack_peek
.align 1
.globl stack_size
.type stack_size, @function
stack_size:
lw a0,0(a0)
ret
.size stack_size, .-stack_size
.align 1
.globl eval_op
.type eval_op, @function
eval_op:
addiw a5,a0,-37
sext.w a3,a5
li a4,10
bgtu a3,a4,.L36
slli a3,a5,32
lla a4,.L31
srli a5,a3,30
add a5,a5,a4
lw a5,0(a5)
add a5,a5,a4
jr a5
.section .rodata
.align 2
.align 2
.L31:
.word .L35-.L31
.word .L36-.L31
.word .L36-.L31
.word .L36-.L31
.word .L36-.L31
.word .L34-.L31
.word .L33-.L31
.word .L36-.L31
.word .L32-.L31
.word .L36-.L31
.word .L30-.L31
.text
.L36:
li a0,0
ret
.L30:
divw a0,a1,a2
ret
.L35:
remw a0,a1,a2
ret
.L34:
mulw a0,a1,a2
ret
.L33:
addw a0,a1,a2
ret
.L32:
subw a0,a1,a2
ret
.size eval_op, .-eval_op
.align 1
.globl eval
.type eval, @function
eval:
addi sp,sp,-112
sd ra,104(sp)
sd s1,88(sp)
sd s3,72(sp)
sd s6,48(sp)
sd s0,96(sp)
sd s2,80(sp)
sd s4,64(sp)
sd s5,56(sp)
sd s7,40(sp)
sd s8,32(sp)
sd s9,24(sp)
addi sp,sp,-2032
mv s3,sp
li a2,1024
li a1,0
mv a0,s3
call memset@plt
addi s1,sp,1024
li a2,1024
li a1,0
mv a0,s1
lla s6,.LANCHOR1
call memset@plt
lw a5,8(s6)
bne a5,zero,.L57
lw a5,4(s6)
li s8,1
sw s8,0(sp)
sw a5,4(sp)
call next_token
lw s2,8(s6)
li s0,0
li s4,10
li s7,1
lla s5,.L50
bne s2,s8,.L92
.L40:
lw s8,0(s6)
addiw s9,s8,-37
bgtu s9,s4,.L91
li a5,1377
srl a5,a5,s9
andi a5,a5,1
bne a5,zero,.L43
.L91:
lw s4,0(sp)
slli s2,s4,2
mv s5,s2
call next_token
beq s0,zero,.L41
slli a5,s0,2
add s1,s1,a5
li a0,10
lla a1,.L60
.L66:
lw a5,0(s1)
li a4,4096
addi a4,a4,-2048
add a4,a4,s2
add a4,a4,sp
addiw s0,s0,-1
addiw s4,s4,-1
addi s2,s2,-4
addiw a5,a5,-37
lw a2,-2048(a4)
add s2,s3,s2
sw s4,0(sp)
sw s0,1024(sp)
sext.w a3,a5
lw a4,0(s2)
bgtu a3,a0,.L71
slli a3,a5,32
srli a5,a3,30
add a5,a5,a1
lw a5,0(a5)
add a5,a5,a1
jr a5
.section .rodata
.align 2
.align 2
.L60:
.word .L64-.L60
.word .L71-.L60
.word .L71-.L60
.word .L71-.L60
.word .L71-.L60
.word .L63-.L60
.word .L62-.L60
.word .L71-.L60
.word .L61-.L60
.word .L71-.L60
.word .L59-.L60
.text
.L71:
li a5,0
.L58:
sw a5,0(s2)
addi s1,s1,-4
beq s0,zero,.L93
.L65:
lw s4,0(sp)
slli s2,s4,2
j .L66
.L59:
divw a5,a4,a2
addi s1,s1,-4
sw a5,0(s2)
bne s0,zero,.L65
.L93:
lw s5,0(sp)
slli s5,s5,2
.L41:
li a5,4096
addi a5,a5,-2048
add a5,a5,s5
add s5,a5,sp
lw a0,-2048(s5)
.L89:
addi sp,sp,2032
ld ra,104(sp)
ld s0,96(sp)
ld s1,88(sp)
ld s2,80(sp)
ld s3,72(sp)
ld s4,64(sp)
ld s5,56(sp)
ld s6,48(sp)
ld s7,40(sp)
ld s8,32(sp)
ld s9,24(sp)
addi sp,sp,112
jr ra
.L61:
subw a5,a4,a2
j .L58
.L62:
addw a5,a4,a2
j .L58
.L63:
mulw a5,a4,a2
j .L58
.L64:
remw a5,a4,a2
j .L58
.L43:
call next_token
beq s0,zero,.L45
sll a0,s7,s9
slli a1,s0,2
andi a6,a0,1057
add a1,s1,a1
andi a0,a0,320
.L46:
lw a5,0(a1)
addiw a5,a5,-37
sext.w a4,a5
bgtu a4,s4,.L55
sll a4,s7,a4
andi a3,a4,1057
bne a3,zero,.L56
andi a4,a4,320
bne a4,zero,.L94
.L55:
bne a6,zero,.L68
bne a0,zero,.L68
.L56:
lw a3,0(sp)
li a2,4096
addi a2,a2,-2048
slli a4,a3,2
add a2,a2,a4
add a2,a2,sp
addiw a3,a3,-1
addiw s0,s0,-1
addi a4,a4,-4
lw a7,-2048(a2)
add a4,s3,a4
sw a3,0(sp)
sw s0,1024(sp)
sext.w a2,a5
lw a3,0(a4)
bgtu a2,s4,.L70
slli a2,a5,32
srli a5,a2,30
add a5,a5,s5
lw a5,0(a5)
add a5,a5,s5
jr a5
.section .rodata
.align 2
.align 2
.L50:
.word .L54-.L50
.word .L70-.L50
.word .L70-.L50
.word .L70-.L50
.word .L70-.L50
.word .L53-.L50
.word .L52-.L50
.word .L70-.L50
.word .L51-.L50
.word .L70-.L50
.word .L49-.L50
.text
.L70:
li a5,0
.L48:
sw a5,0(a4)
addi a1,a1,-4
bne s0,zero,.L46
.L45:
mv s0,s2
li a5,4
.L47:
li a2,4096
addi a3,a2,-2048
add a3,a3,a5
lw a4,8(s6)
sw s0,1024(sp)
add a5,a3,sp
sw s8,-1024(a5)
bne a4,zero,.L57
lw a4,0(sp)
lw a3,4(s6)
addiw a5,a4,1
mv a4,a5
sw a4,0(sp)
slli a5,a5,2
addi a4,a2,-2048
add a4,a4,a5
add a5,a4,sp
sw a3,-2048(a5)
call next_token
lw a5,8(s6)
lw s0,1024(sp)
beq a5,s7,.L40
j .L91
.L94:
beq a6,zero,.L56
.L68:
addiw s0,s0,1
slli a5,s0,2
j .L47
.L51:
subw a5,a3,a7
j .L48
.L52:
addw a5,a3,a7
j .L48
.L53:
mulw a5,a3,a7
j .L48
.L54:
remw a5,a3,a7
j .L48
.L49:
divw a5,a3,a7
j .L48
.L57:
li a0,112
call putch@plt
li a0,97
call putch@plt
li a0,110
call putch@plt
li a0,105
call putch@plt
li a0,99
call putch@plt
li a0,33
call putch@plt
li a0,10
call putch@plt
li a0,-1
j .L89
.L92:
call next_token
li s5,4
j .L41
.size eval, .-eval
.section .text.startup,"ax",@progbits
.align 1
.globl main
.type main, @function
main:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
call getint@plt
mv s0,a0
call getch@plt
call next_token
beq s0,zero,.L96
.L97:
call eval
call putint@plt
addiw s0,s0,-1
li a0,10
call putch@plt
bne s0,zero,.L97
.L96:
ld ra,8(sp)
ld s0,0(sp)
li a0,0
addi sp,sp,16
jr ra
.size main, .-main
.globl cur_token
.globl other
.globl num
.globl last_char
.globl TOKEN_OTHER
.globl TOKEN_NUM
.globl _sysy_idx
.globl _sysy_us
.globl _sysy_s
.globl _sysy_m
.globl _sysy_h
.globl _sysy_l2
.globl _sysy_l1
.globl _sysy_end
.globl _sysy_start
.data
.align 2
.set .LANCHOR0,. + 0
.type last_char, @object
.size last_char, 4
last_char:
.word 32
.bss
.align 3
.set .LANCHOR1,. + 0
.type other, @object
.size other, 4
other:
.zero 4
.type num, @object
.size num, 4
num:
.zero 4
.type cur_token, @object
.size cur_token, 4
cur_token:
.zero 4
.type _sysy_idx, @object
.size _sysy_idx, 4
_sysy_idx:
.zero 4
.type _sysy_us, @object
.size _sysy_us, 4096
_sysy_us:
.zero 4096
.type _sysy_s, @object
.size _sysy_s, 4096
_sysy_s:
.zero 4096
.type _sysy_m, @object
.size _sysy_m, 4096
_sysy_m:
.zero 4096
.type _sysy_h, @object
.size _sysy_h, 4096
_sysy_h:
.zero 4096
.type _sysy_l2, @object
.size _sysy_l2, 4096
_sysy_l2:
.zero 4096
.type _sysy_l1, @object
.size _sysy_l1, 4096
_sysy_l1:
.zero 4096
.type _sysy_end, @object
.size _sysy_end, 16
_sysy_end:
.zero 16
.type _sysy_start, @object
.size _sysy_start, 16
_sysy_start:
.zero 16
.section .rodata
.align 2
.type TOKEN_OTHER, @object
.size TOKEN_OTHER, 4
TOKEN_OTHER:
.word 1
.type TOKEN_NUM, @object
.size TOKEN_NUM, 4
TOKEN_NUM:
.zero 4
.ident "GCC: (Debian 12.2.0-13) 12.2.0"
.section .note.GNU-stack,"",@progbits