If you are on a machine with architecture MIPS
native, you can use the compiler GCC
passing the argument -S
so that it manages the code in assembly
equivalent to the program written in C, for example:
$ gcc -S bissexto.c -o bissexto.asm
Poreḿ, if you’re not in an architecture MIPS
, you will need a cross-compiler
.
In that case, I suggest the Codescape MIPS SDK
that can be obtained here.
Once with the 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 programme in C:
$ ./mips-mti-linux-gnu-gcc -S bissexto.c -o bissexto.asm
aphrodisiac.:
.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?\000"
.align 2
$LC1:
.ascii "%d\000"
.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"
I think it’s not the purpose of the site to make a new code, that is to make everything for you. I would need a specific question at some point that is in trouble. I would not waste time on this. It takes a monster job to make code better than the C compiler will produce, especially if you try this code better in C. The gain in this type of code does not justify the conversion.
– Maniero
Use this code formatting option when it is code that can be executed in the frontend as Javascript, HTML, CSS and so on. Do not use for backend code, such as C that depends on a compiler, for backend code you can use the
{ }
or select the code and press the keysctrl+k
. Here’s how to format your question.– gato
@Maniero I found the question very relevant. I think with the proper tags the question becomes clearer.
– Lacobus
I also found the question good since there are tools for this.
– gfleck