I want to transfer c codes into MIPS which can be ran in QTSpim. For example: Convert
#include<stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
into
.data
msg: .asciiz "Hello World"
.extern foobar 4
.text
.globl main
main: li $v0, 4 # syscall 4 (print_str)
la $a0, msg # argument: string
syscall # print the string
lw $t1, foobar
jr $ra # retrun to caller
I tried gcc -S helloWorld.c in my mac, then I got helloWorld.s below:
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 11, 0 sdk_version 11, 3
.globl _main ## -- Begin function main
.p2align 4, 0x90
_main: ## @main
.cfi_startproc
## %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $16, %rsp
movl $0, -4(%rbp)
leaq L_.str(%rip), %rdi
movb $0, %al
callq _printf
xorl %ecx, %ecx
movl %eax, -8(%rbp) ## 4-byte Spill
movl %ecx, %eax
addq $16, %rsp
popq %rbp
retq
.cfi_endproc
## -- End function
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "Hello, World!"
.subsections_via_symbols
I have searched a few but there are no clear answers for that. I am quite new to MIPS as I found there are a lot of assembly languages of MIPS? Any explanation or solution will be appreciated. Thanks in advance.