#include #include #define STDOUT_FILENO 1 # # For details refere to: # # [+] http://www.linux-mips.org/wiki/PIC_code # # MIPS(r) Processor Supplement, 32-bit ABI # [+] http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf # .data msg_str: .asciiz "hello, world!\n" .set msg_len, . - msg_str - 1 fmt_str: .asciiz "write %d bytes\n" .set fmt_len, . - fmt_str - 1 fmt_str2: .asciiz "%d %d %d %d %d %d\n" fmt_str3: .asciiz "string length is %d bytes\n" .text .globl main .extern printf # # int strlen(const char *str) # # This function doesn't need PIC mess because it # uses no global symbols. # strlen: move v0, zero 1: lbu t0, (a0) beq t0, zero, 2f addiu v0, v0, 1 addiu a0, a0, 1 b 1b 2: jr ra main: .ent main # PIC-compatible prologue .frame sp, 40, ra .set noreorder .cpload t9 .set reorder subu sp, sp, 40 sw ra, 36(sp) .cprestore 32 # write(STDOUT_FILENO, msg_str, msg_len) li a0, STDOUT_FILENO la a1, msg_str li a2, msg_len li v0, __NR_write syscall # printf(fmt_str, a1) la a0, fmt_str move a1, v0 jal printf # printf(fmt_str2, 0, 1, 2, 3, 4, 5) la a0, fmt_str2 li a1, 0 li a2, 1 li a3, 2 li t0, 3 sw t0, 16(sp) li t0, 4 sw t0, 20(sp) li t0, 5 sw t0, 24(sp) jal printf # strlen(fmt_str2) la a0, fmt_str2 jal strlen # printf(fmt_str3, a1) la a0, fmt_str3 move a1, v0 jal printf # PIC-compatible epilogue lw ra, 36(sp) addiu sp, sp, 40 jr ra .end main