Can someone translate these C codes into mips assembly code

You could use this http://reliant.colab.duke.edu/c2mips/ trans of c to Mips assembly. And the following should be work.

.file   1 ""
    .section .mdebug.abi32
    .previous
    .gnu_attribute 4, 1
    .abicalls
    .rdata
    .align  2
$LC0:
    .ascii  "Input the string: \000"
    .align  2
$LC1:
    .ascii  "%s\000"
    .align  2
$LC2:
    .ascii  "*%s*\012\000"
    .text
    .align  2
    .globl  main
$LFB0 = .
    .set    nomips16
    .ent    main
    .type   main, @function
main:
    .frame  $fp,144,$31     # vars= 112, regs= 2/0, args= 16, gp= 8
    .mask   0xc0000000,-4
    .fmask  0x00000000,0
    .set    noreorder
    .cpload $25
    .set    nomacro

    addiu   $sp,$sp,-144
$LCFI0:
    sw  $31,140($sp)
$LCFI1:
    sw  $fp,136($sp)
    movz    $31,$31,$0
$LCFI2:
    move    $fp,$sp
$LCFI3:
    .cprestore  16
    sw  $4,144($fp)
    sw  $5,148($fp)
    lw  $2,%got($LC0)($28)
    nop
    addiu   $4,$2,%lo($LC0)
    lw  $2,%call16(printf)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    addiu   $2,$fp,36
    lw  $3,%got($LC1)($28)
    nop
    addiu   $4,$3,%lo($LC1)
    move    $5,$2
    lw  $2,%call16(scanf)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    addiu   $2,$fp,36
    move    $4,$2
    lw  $2,%call16(strlen)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    sw  $2,32($fp)
    sw  $0,28($fp)
    b   $L2
    nop

$L3:
    li  $4,42           # 0x2a
    lw  $2,%call16(putchar)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    lw  $2,28($fp)
    nop
    addiu   $2,$2,1
    sw  $2,28($fp)
$L2:
    lw  $2,32($fp)
    nop
    addiu   $3,$2,2
    lw  $2,28($fp)
    nop
    slt $2,$2,$3
    andi    $2,$2,0x00ff
    bne $2,$0,$L3
    nop

    li  $4,10           # 0xa
    lw  $2,%call16(putchar)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    addiu   $2,$fp,36
    lw  $3,%got($LC2)($28)
    nop
    addiu   $4,$3,%lo($LC2)
    move    $5,$2
    lw  $2,%call16(printf)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    sw  $0,24($fp)
    b   $L4
    nop

$L5:
    li  $4,42           # 0x2a
    lw  $2,%call16(putchar)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    lw  $2,24($fp)
    nop
    addiu   $2,$2,1
    sw  $2,24($fp)
$L4:
    lw  $2,32($fp)
    nop
    addiu   $3,$2,2
    lw  $2,24($fp)
    nop
    slt $2,$2,$3
    andi    $2,$2,0x00ff
    bne $2,$0,$L5
    nop

    li  $4,10           # 0xa
    lw  $2,%call16(putchar)($28)
    nop
    move    $25,$2
    jalr    $25
    nop

    lw  $28,16($fp)
    move    $2,$0
    move    $sp,$fp
    lw  $31,140($sp)
    lw  $fp,136($sp)
    addiu   $sp,$sp,144
    j   $31
    nop

    .set    macro
    .set    reorder
    .end    main
$LFE0:
    .size   main, .-main
    .section    .eh_frame,"aw",@progbits
$Lframe1:
    .4byte  $LECIE1-$LSCIE1
$LSCIE1:
    .4byte  0x0
    .byte   0x1
    .globl  __gxx_personality_v0
    .ascii  "zP\000"
    .uleb128 0x1
    .sleb128 -4
    .byte   0x1f
    .uleb128 0x5
    .byte   0x0
    .4byte  __gxx_personality_v0
    .byte   0xc
    .uleb128 0x1d
    .uleb128 0x0
    .align  2
$LECIE1:
$LSFDE1:
    .4byte  $LEFDE1-$LASFDE1
$LASFDE1:
    .4byte  $LASFDE1-$Lframe1
    .4byte  $LFB0
    .4byte  $LFE0-$LFB0
    .uleb128 0x0
    .byte   0x4
    .4byte  $LCFI0-$LFB0
    .byte   0xe
    .uleb128 0x90
    .byte   0x4
    .4byte  $LCFI2-$LCFI0
    .byte   0x11
    .uleb128 0x1e
    .sleb128 2
    .byte   0x11
    .uleb128 0x1f
    .sleb128 1
    .byte   0x4
    .4byte  $LCFI3-$LCFI2
    .byte   0xd
    .uleb128 0x1e
    .align  2
$LEFDE1:
    .ident  "GCC: (Debian 4.4.5-8) 4.4.5"

Browse More Popular Posts

Leave a Comment