Question & Answer: MIPS assembly code for adding (addition of) and subtracting (subtraction of) two signed numbers (positive and…..

MIPS assembly code for adding (addition of) and subtracting (subtraction of) two signed numbers (positive and negative numbers) . Need code for both methods. Using registers and hardware only aka “logical operations”. Cannot use just MIPS add and sub. Need to use bit operations.

Expert Answer

 For addition:
.file   1 ""
        .section .mdebug.abi32
        .previous
        .gnu_attribute 4, 1
        .abicalls
        .rdata
        .align  2
$LC0:
        .ascii  "%d %d00"
        .align  2
$LC1:
        .ascii  "%d00"
        .text
        .align  2
        .globl  main
$LFB0 = .
        .set    nomips16
        .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
        .cpload $25
        .set    nomacro
        
        addiu   $sp,$sp,-48
$LCFI0:
        sw      $31,44($sp)
$LCFI1:
        sw      $fp,40($sp)
        movz    $31,$31,$0
$LCFI2:
        move    $fp,$sp
$LCFI3:
        .cprestore      16
        addiu   $3,$fp,28
        addiu   $2,$fp,32
        lw      $4,%got($LC0)($28)
        nop
        addiu   $4,$4,%lo($LC0)
        move    $5,$3
        move    $6,$2
        lw      $2,%call16(scanf)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        lw      $3,28($fp)
        lw      $2,32($fp)
        move    $4,$3
        move    $5,$2
        lw      $2,%got(_Z3sumii)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        sw      $2,24($fp)
        lw      $2,%got($LC1)($28)
        nop
        addiu   $4,$2,%lo($LC1)
        lw      $5,24($fp)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        move    $2,$0
        move    $sp,$fp
        lw      $31,44($sp)
        lw      $fp,40($sp)
        addiu   $sp,$sp,48
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    main
$LFE0:
        .size   main, .-main
        .align  2
        .globl  _Z3sumii
$LFB1 = .
        .set    nomips16
        .ent    _Z3sumii
        .type   _Z3sumii, @function
_Z3sumii:
        .frame  $fp,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        
        addiu   $sp,$sp,-8
$LCFI4:
        sw      $fp,4($sp)
$LCFI5:
        move    $fp,$sp
        movz    $31,$31,$0
$LCFI6:
        sw      $4,8($fp)
        sw      $5,12($fp)
        lw      $3,8($fp)
        lw      $2,12($fp)
        nop
        addu    $2,$3,$2
        move    $sp,$fp
        lw      $fp,4($sp)
        addiu   $sp,$sp,8
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    _Z3sumii
$LFE1:
        .size   _Z3sumii, .-_Z3sumii
        .section        .eh_frame,"aw",@progbits
$Lframe1:
        .4byte  $LECIE1-$LSCIE1
$LSCIE1:
        .4byte  0x0
        .byte   0x1
        .globl  __gxx_personality_v0
        .ascii  "zP00"
        .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 0x30
        .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"

For Substraction

.file   1 ""
        .section .mdebug.abi32
        .previous
        .gnu_attribute 4, 1
        .abicalls
        .rdata
        .align  2
$LC0:
        .ascii  "%d %d00"
        .align  2
$LC1:
        .ascii  "%d00"
        .text
        .align  2
        .globl  main
$LFB0 = .
        .set    nomips16
        .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
        .cpload $25
        .set    nomacro
        
        addiu   $sp,$sp,-48
$LCFI0:
        sw      $31,44($sp)
$LCFI1:
        sw      $fp,40($sp)
        movz    $31,$31,$0
$LCFI2:
        move    $fp,$sp
$LCFI3:
        .cprestore      16
        addiu   $3,$fp,28
        addiu   $2,$fp,32
        lw      $4,%got($LC0)($28)
        nop
        addiu   $4,$4,%lo($LC0)
        move    $5,$3
        move    $6,$2
        lw      $2,%call16(scanf)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        lw      $3,28($fp)
        lw      $2,32($fp)
        move    $4,$3
        move    $5,$2
        lw      $2,%got(_Z4diffii)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        sw      $2,24($fp)
        lw      $2,%got($LC1)($28)
        nop
        addiu   $4,$2,%lo($LC1)
        lw      $5,24($fp)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        jalr    $25
        nop

        lw      $28,16($fp)
        move    $2,$0
        move    $sp,$fp
        lw      $31,44($sp)
        lw      $fp,40($sp)
        addiu   $sp,$sp,48
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    main
$LFE0:
        .size   main, .-main
        .align  2
        .globl  _Z4diffii
$LFB1 = .
        .set    nomips16
        .ent    _Z4diffii
        .type   _Z4diffii, @function
_Z4diffii:
        .frame  $fp,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        
        addiu   $sp,$sp,-8
$LCFI4:
        sw      $fp,4($sp)
$LCFI5:
        move    $fp,$sp
        movz    $31,$31,$0
$LCFI6:
        sw      $4,8($fp)
        sw      $5,12($fp)
        lw      $3,8($fp)
        lw      $2,12($fp)
        nop
        subu    $2,$3,$2
        move    $sp,$fp
        lw      $fp,4($sp)
        addiu   $sp,$sp,8
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    _Z4diffii
$LFE1:
        .size   _Z4diffii, .-_Z4diffii
        .section        .eh_frame,"aw",@progbits
$Lframe1:
        .4byte  $LECIE1-$LSCIE1
$LSCIE1:
        .4byte  0x0
        .byte   0x1
        .globl  __gxx_personality_v0
        .ascii  "zP00"
        .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 0x30
        .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"
Still stressed from student homework?
Get quality assistance from academic writers!