-
-
Notifications
You must be signed in to change notification settings - Fork 324
Open
Description
I'm using selfie -s
to output risc-u asm.
from the examples:
// global variable for pointing to the "Hello World! " string
uint64_t* foo;
// main procedure for printing "Hello World! " on the console
uint64_t* main() {
// point to the "Hello World! " string
foo = "Hello World! ";
/* strings are actually stored in chunks of 8 characters in memory,
that is, here as "Hello Wo", and "rld! " which allows us to
print them conveniently in chunks of 8 characters at a time */
// as long as there are characters print them
while (*foo != 0) {
// 1 means that we print to the console
// foo points to a chunk of 8 characters
// 8 means that we print 8 characters
write(1, foo, 8);
// go to the next chunk of 8 characters
foo = foo + 1;
}
}
this is translated to this asm:
.global _start
_start:
lui t0,0x11
addi t0,t0,40
addi gp,t0,0
addi a0,zero,0
addi a7,zero,214
ecall
addi a0,a0,7
addi t0,zero,8
remu t0,a0,t0
sub a0,a0,t0
addi a7,zero,214
ecall
sd a0,-8(gp)
ld t0,0(sp)
addi sp,sp,-8
sd t0,0(sp)
addi t0,sp,16
sd t0,8(sp)
jal ra,61
addi sp,sp,-8
sd a0,0(sp)
ld a0,0(sp)
addi sp,sp,8
addi a7,zero,93
ecall
ld a0,0(sp)
addi sp,sp,8
ld a1,0(sp)
addi sp,sp,8
ld a2,0(sp)
addi sp,sp,8
addi a7,zero,63
ecall
jalr zero,0(ra)
ld a0,0(sp)
addi sp,sp,8
ld a1,0(sp)
addi sp,sp,8
ld a2,0(sp)
addi sp,sp,8
addi a7,zero,64
ecall
jalr zero,0(ra)
ld a1,0(sp)
addi sp,sp,8
ld a2,0(sp)
addi sp,sp,8
ld a3,0(sp)
addi sp,sp,8
addi a0,zero,-100
addi a7,zero,56
ecall
jalr zero,0(ra)
ld t0,0(sp)
addi sp,sp,8
addi t0,t0,7
addi t1,zero,8
remu t1,t0,t1
sub t0,t0,t1
ld t1,-8(gp)
add a0,t1,t0
addi a7,zero,214
ecall
beq a0,t1,2
beq zero,zero,4
beq zero,t0,3
addi a0,zero,0
beq zero,zero,3
sd a0,-8(gp)
addi a0,t1,0
jalr zero,0(ra)
ld a0,0(sp)
addi sp,sp,8
ld a1,0(sp)
addi sp,sp,8
addi a7,zero,401
ecall
addi a0,a6,0
jalr zero,0(ra)
addi sp,sp,-8
sd ra,0(sp)
addi sp,sp,-8
sd s0,0(sp)
addi s0,sp,0
addi t0,zero,-40
add t0,gp,t0
sd t0,-16(gp)
ld t0,-16(gp)
ld t0,0(t0)
addi t1,zero,0
sub t0,t1,t0
sltu t0,zero,t0
beq t0,zero,16
addi t0,zero,1
addi sp,sp,-24
sd t0,0(sp)
ld t0,-16(gp)
sd t0,8(sp)
addi t0,zero,8
sd t0,16(sp)
jal ra,-66
ld t0,-16(gp)
addi t1,zero,1
addi t2,zero,8
mul t1,t1,t2
add t0,t0,t1
sd t0,-16(gp)
jal zero,-20
addi a0,zero,0
ld s0,0(sp)
addi sp,sp,8
ld ra,0(sp)
addi sp,sp,8
jalr zero,0(ra)
.8byte 0x6F57206F6C6C6548
.8byte 0x2020202021646C72
.8byte 0x0
.8byte 0x0
.8byte 0x0```
maybe my as or ld command are not right?
```bash
riscv64-unknown-elf-as -march=rv64g -mabi=lp64 my.s -o /tmp/test.riscv.o
riscv64-unknown-elf-ld -nostdlib -z execstack /tmp/test.riscv.o -o /tmp/test.riscv.elf
/tmp/test.riscv.o: in function `_start':
(.text+0x110): relocation truncated to fit: R_RISCV_JAL against `*UND*'
Metadata
Metadata
Assignees
Labels
No labels