If you are on a machine with a native MIPS
architecture, you can use the GCC
compiler by passing the -S
argument so that it generates the code in assembly
equivalent to the program written in C, for example:
$ gcc -S bissexto.c -o bissexto.asm
Poreḿ, if you are not in a MIPS
architecture, you will need a cross-compiler
.
In this case, I suggest the Codescape MIPS SDK
that can be obtained here .
Once with Codescape MIPS SDK
installed:
$ pwd
/opt/imgtec/Toolchains/mips-mti-linux-gnu/2016.05-03/bin
$ ls -al
total 136060
drwxrwxr-x 2 root root 4096 Oct 3 20:49 .
drwxrwxr-x 9 root root 4096 Oct 3 20:46 ..
-rwxr-xr-x 1 root root 5151584 Jun 26 2016 mips-mti-linux-gnu-addr2line
-rwxr-xr-x 1 root root 5320040 Jun 26 2016 mips-mti-linux-gnu-ar
-rwxr-xr-x 1 root root 7876560 Jun 26 2016 mips-mti-linux-gnu-as
-rwxr-xr-x 1 root root 3351704 Jun 26 2016 mips-mti-linux-gnu-c++
-rwxr-xr-x 1 root root 5106592 Jun 26 2016 mips-mti-linux-gnu-c++filt
-rwxr-xr-x 1 root root 3347032 Jun 26 2016 mips-mti-linux-gnu-cpp
-rwxr-xr-x 1 root root 100104 Jun 26 2016 mips-mti-linux-gnu-elfedit
-rwxr-xr-x 1 root root 3351704 Jun 26 2016 mips-mti-linux-gnu-g++
-rwxr-xr-x 1 root root 3343240 Jun 26 2016 mips-mti-linux-gnu-gcc
-rwxr-xr-x 1 root root 3343240 Jun 26 2016 mips-mti-linux-gnu-gcc-4.9.2
-rwxr-xr-x 1 root root 145264 Jun 26 2016 mips-mti-linux-gnu-gcc-ar
-rwxr-xr-x 1 root root 145056 Jun 26 2016 mips-mti-linux-gnu-gcc-nm
-rwxr-xr-x 1 root root 145064 Jun 26 2016 mips-mti-linux-gnu-gcc-ranlib
-rwxr-xr-x 1 root root 2313536 Jun 26 2016 mips-mti-linux-gnu-gcov
-rwxr-xr-x 1 root root 30093240 Jun 26 2016 mips-mti-linux-gnu-gdb
-rwxr-xr-x 1 root root 3352168 Jun 26 2016 mips-mti-linux-gnu-gfortran
-rwxr-xr-x 1 root root 5681544 Jun 26 2016 mips-mti-linux-gnu-gprof
-rwxr-xr-x 1 root root 7715008 Jun 26 2016 mips-mti-linux-gnu-ld
-rwxr-xr-x 1 root root 7715008 Jun 26 2016 mips-mti-linux-gnu-ld.bfd
-rwxr-xr-x 1 root root 5188192 Jun 26 2016 mips-mti-linux-gnu-nm
-rwxr-xr-x 1 root root 6138528 Jun 26 2016 mips-mti-linux-gnu-objcopy
-rwxr-xr-x 1 root root 7251864 Jun 26 2016 mips-mti-linux-gnu-objdump
-rwxr-xr-x 1 root root 5320040 Jun 26 2016 mips-mti-linux-gnu-ranlib
-rwxr-xr-x 1 root root 1345744 Jun 26 2016 mips-mti-linux-gnu-readelf
-rwxr-xr-x 1 root root 5142248 Jun 26 2016 mips-mti-linux-gnu-size
-rwxr-xr-x 1 root root 5141808 Jun 26 2016 mips-mti-linux-gnu-strings
-rwxr-xr-x 1 root root 6138584 Jun 26 2016 mips-mti-linux-gnu-strip
You can use the compiler mips-mti-linux-gnu-gcc
to generate the code assembly
equivalent to the program in C:
$ ./mips-mti-linux-gnu-gcc -S bissexto.c -o bissexto.asm
Bissexto.asm:
.file 1 "bissexto.c"
.section .mdebug.abi32
.previous
.nan legacy
.module fp=xx
.module nooddspreg
.abicalls
.option pic0
.globl tab
.data
.align 2
.type tab, @object
.size tab, 80
tab:
.word 2016
.word 2012
.word 2008
.word 2004
.word 2000
.word 1916
.word 1911
.word 1908
.word 1904
.word 1900
.word 1861
.word 1857
.word 1852
.word 1846
.word 1844
.word 1728
.word 1727
.word 1726
.word 1725
.word 1723
.globl cnt
.section .bss,"aw",@nobits
.align 2
.type cnt, @object
.size cnt, 4
cnt:
.space 4
.globl resultado
.align 2
.type resultado, @object
.size resultado, 20
resultado:
.space 20
.rdata
.align 2
$LC0:
.ascii "Qual linha deseja verificar?$ gcc -S bissexto.c -o bissexto.asm
0"
.align 2
$LC1:
.ascii "%d$ pwd
/opt/imgtec/Toolchains/mips-mti-linux-gnu/2016.05-03/bin
$ ls -al
total 136060
drwxrwxr-x 2 root root 4096 Oct 3 20:49 .
drwxrwxr-x 9 root root 4096 Oct 3 20:46 ..
-rwxr-xr-x 1 root root 5151584 Jun 26 2016 mips-mti-linux-gnu-addr2line
-rwxr-xr-x 1 root root 5320040 Jun 26 2016 mips-mti-linux-gnu-ar
-rwxr-xr-x 1 root root 7876560 Jun 26 2016 mips-mti-linux-gnu-as
-rwxr-xr-x 1 root root 3351704 Jun 26 2016 mips-mti-linux-gnu-c++
-rwxr-xr-x 1 root root 5106592 Jun 26 2016 mips-mti-linux-gnu-c++filt
-rwxr-xr-x 1 root root 3347032 Jun 26 2016 mips-mti-linux-gnu-cpp
-rwxr-xr-x 1 root root 100104 Jun 26 2016 mips-mti-linux-gnu-elfedit
-rwxr-xr-x 1 root root 3351704 Jun 26 2016 mips-mti-linux-gnu-g++
-rwxr-xr-x 1 root root 3343240 Jun 26 2016 mips-mti-linux-gnu-gcc
-rwxr-xr-x 1 root root 3343240 Jun 26 2016 mips-mti-linux-gnu-gcc-4.9.2
-rwxr-xr-x 1 root root 145264 Jun 26 2016 mips-mti-linux-gnu-gcc-ar
-rwxr-xr-x 1 root root 145056 Jun 26 2016 mips-mti-linux-gnu-gcc-nm
-rwxr-xr-x 1 root root 145064 Jun 26 2016 mips-mti-linux-gnu-gcc-ranlib
-rwxr-xr-x 1 root root 2313536 Jun 26 2016 mips-mti-linux-gnu-gcov
-rwxr-xr-x 1 root root 30093240 Jun 26 2016 mips-mti-linux-gnu-gdb
-rwxr-xr-x 1 root root 3352168 Jun 26 2016 mips-mti-linux-gnu-gfortran
-rwxr-xr-x 1 root root 5681544 Jun 26 2016 mips-mti-linux-gnu-gprof
-rwxr-xr-x 1 root root 7715008 Jun 26 2016 mips-mti-linux-gnu-ld
-rwxr-xr-x 1 root root 7715008 Jun 26 2016 mips-mti-linux-gnu-ld.bfd
-rwxr-xr-x 1 root root 5188192 Jun 26 2016 mips-mti-linux-gnu-nm
-rwxr-xr-x 1 root root 6138528 Jun 26 2016 mips-mti-linux-gnu-objcopy
-rwxr-xr-x 1 root root 7251864 Jun 26 2016 mips-mti-linux-gnu-objdump
-rwxr-xr-x 1 root root 5320040 Jun 26 2016 mips-mti-linux-gnu-ranlib
-rwxr-xr-x 1 root root 1345744 Jun 26 2016 mips-mti-linux-gnu-readelf
-rwxr-xr-x 1 root root 5142248 Jun 26 2016 mips-mti-linux-gnu-size
-rwxr-xr-x 1 root root 5141808 Jun 26 2016 mips-mti-linux-gnu-strings
-rwxr-xr-x 1 root root 6138584 Jun 26 2016 mips-mti-linux-gnu-strip
0"
.text
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $fp,48,$31 # vars= 16, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
move $fp,$sp
$L2:
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
jal printf
nop
addiu $3,$fp,32
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
move $5,$3
jal __isoc99_scanf
nop
lw $2,32($fp)
slt $2,$2,4
beq $2,$0,$L2
nop
sw $0,24($fp)
b $L3
nop
$L5:
lw $2,32($fp)
move $4,$2
lw $5,24($fp)
jal f_bissexto
nop
sw $2,28($fp)
lw $2,28($fp)
beq $2,$0,$L4
nop
lui $2,%hi(cnt)
lw $3,%lo(cnt)($2)
lui $2,%hi(resultado)
sll $3,$3,2
addiu $2,$2,%lo(resultado)
addu $2,$3,$2
lw $3,28($fp)
sw $3,0($2)
lui $2,%hi(cnt)
lw $2,%lo(cnt)($2)
addiu $3,$2,1
lui $2,%hi(cnt)
sw $3,%lo(cnt)($2)
$L4:
lw $2,24($fp)
addiu $2,$2,1
sw $2,24($fp)
$L3:
lw $2,24($fp)
slt $2,$2,5
bne $2,$0,$L5
nop
jal imprimir
nop
move $2,$0
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
jr $31
nop
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (Codescape GNU Tools 2016.05-03 for MIPS MTI Linux) 4.9.2"