Skip to content

Instantly share code, notes, and snippets.

@aDotInTheVoid
Created July 20, 2023 21:58
Show Gist options
  • Save aDotInTheVoid/d621b54755883750eb32d4fb8f3ae69a to your computer and use it in GitHub Desktop.
Save aDotInTheVoid/d621b54755883750eb32d4fb8f3ae69a to your computer and use it in GitHub Desktop.
# BEGIN RT
.syntax unified
.section .note.GNU-stack, "", %progbits
.data
.L_RT_print_int:
.asciz "%d"
.L_RT_print_char:
.asciz "%c"
.L_RT_print_true:
.asciz "true"
.L_RT_print_false:
.asciz "false"
.L_RT_print_ptr:
.asciz "%p"
.L_RT_print_string:
.asciz "%.*s"
.L_RT_rt_error:
.asciz "#runtime_error#"
.text
rt_print_int:
ldr r0, =.L_RT_print_int
b printf
rt_print_char:
ldr r0, =.L_RT_print_char
b printf
rt_print_ptr:
ldr r0, =.L_RT_print_ptr
b printf
rt_print_bool:
# Bool in in r1
ldr r2, =.L_RT_print_true
ldr r0, =.L_RT_print_false
cmp r1, #0
movne r0, r2
b printf
rt_println:
mov r0, #10
b putchar
rt_print_string:
mov r2, r1
ldr r1, [r2, #-4]
ldr r0, =.L_RT_print_string
b printf
# https://godbolt.org/z/3q9cfox17
rt_error:
ldr r0, .LCPI0_0
.LPC0_0:
add r0, pc, r0
bl printf
mov r0, #255
bl exit
.LCPI0_0:
.long .L.str-(.LPC0_0+8)
rt_error_div0:
ldr r0, .LCPI1_0
.LPC1_0:
add r0, pc, r0
bl puts
mov r0, #255
bl exit
.LCPI1_0:
.long .Lstr-(.LPC1_0+8)
rt_error_sigsegv:
ldr r0, .LCPI2_0
.LPC2_0:
add r0, pc, r0
bl puts
mov r0, #255
bl exit
.LCPI2_0:
.long .Lstr.5-(.LPC2_0+8)
rt_array_new_word:
push {r4, r5, r11, lr}
mov r4, r0
mov r0, #4
mov r5, r1
add r0, r0, r4, lsl #2
bl malloc
mov r1, r0
sub r2, r5, #4
str r4, [r1], #4
.LBB3_1: @ =>This Inner Loop Header: Depth=1
cmp r4, #0
beq .LBB3_3
ldr r3, [r2, r4, lsl #2]
sub r4, r4, #1
str r3, [r1], #4
b .LBB3_1
.LBB3_3:
add r0, r0, #4
pop {r4, r5, r11, lr}
mov pc, lr
rt_array_new_byte:
push {r4, r5, r11, lr}
mov r4, r0
add r0, r0, #4
mov r5, r1
bl malloc
str r4, [r0], #4
sub r1, r5, #4
mov r2, r0
.LBB4_1: @ =>This Inner Loop Header: Depth=1
cmp r4, #0
popeq {r4, r5, r11, lr}
moveq pc, lr
ldr r3, [r1, r4, lsl #2]
sub r4, r4, #1
strb r3, [r2], #1
b .LBB4_1
rt_read_char:
push {r2, r3, r4, lr}
cmp r0, #4
bls .LBB5_2
mov r4, r0
ldr r0, .LCPI5_0
add r1, sp, #7
.LPC5_0:
add r0, pc, r0
bl __isoc99_scanf
cmp r0, #1
ldrbeq r0, [sp, #7]
strbeq r0, [r4]
pop {r2, r3, r4, lr}
mov pc, lr
.LBB5_2:
bl rt_error
.LCPI5_0:
.long .L.str.3-(.LPC5_0+8)
rt_read_int:
push {r2, r3, r4, lr}
cmp r0, #4
bls .LBB6_2
mov r4, r0
ldr r0, .LCPI6_0
add r1, sp, #4
.LPC6_0:
add r0, pc, r0
bl __isoc99_scanf
cmp r0, #1
ldreq r0, [sp, #4]
streq r0, [r4]
pop {r2, r3, r4, lr}
mov pc, lr
.LBB6_2:
bl rt_error
.LCPI6_0:
.long .L.str.4-(.LPC6_0+8)
rt_pair_new:
push {r4, r5, r11, lr}
mov r5, r0
mov r0, #8
mov r4, r1
bl malloc
stm r0, {r4, r5}
pop {r4, r5, r11, lr}
mov pc, lr
rt_init:
ldr r1, .LCPI8_0
mov r0, #11
.LPC8_0:
add r1, pc, r1
b signal
.LCPI8_0:
.long rt_error_sigsegv-(.LPC8_0+8)
rt_get_array_word:
cmp r0, #0
bmi .LBB9_2
ldr r2, [r1, #-4]
cmp r2, r0
ldrgt r0, [r1, r0, lsl #2]
movgt pc, lr
.LBB9_2:
bl rt_error
rt_get_array_byte:
cmp r0, #0
bmi .LBB10_2
ldr r2, [r1, #-4]
cmp r2, r0
ldrbgt r0, [r1, r0]
movgt pc, lr
.LBB10_2:
bl rt_error
.data
.L.str:
.asciz "#runtime_error#"
.L.str.3:
.asciz " %c"
.L.str.4:
.asciz "%d"
.Lstr:
.asciz "fatal error: division by zero"
.Lstr.5:
.asciz "fatal error: null pointer dereference"
.global main
.text
# END RT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment