added code
This commit is contained in:
parent
e15aadbb5e
commit
51bef30657
2 changed files with 95 additions and 0 deletions
78
funnyhello.s
Normal file
78
funnyhello.s
Normal file
|
@ -0,0 +1,78 @@
|
|||
.text
|
||||
.globl _start
|
||||
|
||||
_start:
|
||||
ld a0, 8(sp)
|
||||
jal ra, puts
|
||||
la a0, helloworld
|
||||
jal ra, puts
|
||||
la a0, incomingflag
|
||||
jal ra, puts
|
||||
|
||||
|
||||
ld t2, flagmyballs
|
||||
ror t2, t2, 01
|
||||
la t1, flagmyballs
|
||||
sd t2, 0(t1)
|
||||
|
||||
la a0, flagmyballs
|
||||
jal ra, puts
|
||||
j exit
|
||||
|
||||
len:
|
||||
mv t0, a0
|
||||
mv t1, t0
|
||||
|
||||
lenloop:
|
||||
lb t2, (t1)
|
||||
beq t2, x0, lencleanup
|
||||
addi t1, t1, 1
|
||||
j lenloop
|
||||
|
||||
lencleanup:
|
||||
sub a0, t1, t0
|
||||
ret
|
||||
|
||||
puts:
|
||||
#here a0 should be the pointer to the string
|
||||
|
||||
#save s2 becuase we are gonna use it
|
||||
addi sp, sp, -16
|
||||
sd s2, 12(sp)
|
||||
|
||||
#save a0 because we need it later
|
||||
mv s2, a0
|
||||
|
||||
#get length because the stdout systemcall needs it in a2
|
||||
addi sp, sp, -16 # Allocate stack space
|
||||
sd ra, 12(sp) # Save return address
|
||||
jal ra, len
|
||||
ld ra, 12(sp) # Restore return address
|
||||
addi sp, sp, 16 # Deallocate stack space
|
||||
#a0 should be the length
|
||||
mv a2, a0 #stdout expects it in a2
|
||||
|
||||
li a0, 1 # file descriptor = 1 (stdout)
|
||||
li a7, 64 # syscall write (64)
|
||||
|
||||
mv a1, s2 #this should still be the pointer to the text
|
||||
|
||||
#restore s2 for the next guy
|
||||
ld s2, 12(sp)
|
||||
addi sp, sp, 16
|
||||
|
||||
ecall
|
||||
|
||||
ret
|
||||
|
||||
exit:
|
||||
li a0, 0 # exit code
|
||||
li a7, 93 # syscall exit
|
||||
ecall
|
||||
|
||||
.data
|
||||
helloworld: .asciz "Hello! It works!!!\n"
|
||||
incomingflag: .asciz "The flag you gotta fix should be right after the newline\n"
|
||||
flagmyballs:
|
||||
# .dword 0x7370617263363400
|
||||
.dword 0x0343663726170730
|
17
hello.s
Normal file
17
hello.s
Normal file
|
@ -0,0 +1,17 @@
|
|||
.globl _start
|
||||
|
||||
_start:
|
||||
li a0, 1 # file descriptor = 1 (stdout)
|
||||
la a1, string # buffer
|
||||
li a2, 19 # size
|
||||
li a7, 64 # syscall write (64)
|
||||
ecall
|
||||
|
||||
_end:
|
||||
|
||||
li a0, 0 # exit code
|
||||
li a7, 93 # syscall exit
|
||||
ecall
|
||||
|
||||
|
||||
string: .asciz "Hello! It works!!!\n"
|
Loading…
Reference in a new issue