nano hello.s
# File: hello.s -- Say Hello to MIPS Assembly Language Programmer # Author: falcon <wuzhangjin(at)gmail.com>, 2025/01/17 # Ref: # [*] http://www.tldp.org/HOWTO/Assembly-HOWTO/mips.html # [*] MIPS Assembly Language Programmer's Guide # [*] See MIPS Run Linux(second version) # Compile: # $ gcc -o hello hello.s # or # $ as -o hello.o hello.s # $ ld -e main -o hello hello.o .text .globl main main: .set noreorder .cpload $gp # setup the pointer to global data .set reorder # print sth. via sys_write li $a0, 1 # print to standard ouput la $a1, stradr # set the string address lw $a2, strlen # set the string length li $v0, 4004 # index of sys_write: # __NR_write in /usr/include/asm/unistd.h syscall # causes a system call trap. # exit via sys_exit move $a0, $0 # exit status as 0 li $v0, 4001 # index of sys_exit # __NR_exit in /usr/include/asm/unistd.h syscall .rdata stradr: .asciiz "hello, world!\n" strlen: .word . - stradr # current address - the string address # end
root@Arduino:/mnt/sda1# gcc -o hello hello.s root@Arduino:/mnt/sda1# ./hello hello, world!
Comments powered by CComment