Question

In: Computer Science

- sparc assembly - *Write a program that takes four 32-bit integers (A,B,C,D) in hexadecimal form...

- sparc assembly -

*Write a program that takes four 32-bit integers (A,B,C,D) in hexadecimal form and calculates A*B + C*D.

(Assumption: User input is 32-bit 0 or positive. The result is expressed in 64 bits.)

[result example]

bash $ assm

Hex value? ffffffff

Hex value? 8

Hex value? ffffffff

Hex value? 8

Result is 0000000f fffffff0

Solutions

Expert Solution

Please give positive ratings for my effort. Thanks.

PROGRAM

.LC0:

        .ascii  "\012Result is :  \000"

.LC1:

        .ascii  " \000"

dectohex(long long):

        daddiu  $sp,$sp,-1088

        sd      $31,1080($sp)

        sd      $fp,1072($sp)

        sd      $28,1064($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(dectohex(long long))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(dectohex(long long))))

        sd      $4,1040($fp)

        sd      $0,0($fp)

.L7:

        ld      $2,1040($fp)

        beq     $2,$0,.L2

        nop

        sw      $0,24($fp)

        ld      $3,1040($fp)

        li      $2,-1                 # 0xffffffffffffffff

        dsll    $2,$2,63

        ori     $2,$2,0xf

        and     $2,$3,$2

        bgez    $2,.L3

        nop

        daddiu  $2,$2,-1

        li      $3,-16                  # 0xfffffffffffffff0

        or      $2,$2,$3

        daddiu  $2,$2,1

.L3:

        sw      $2,24($fp)

        lw      $2,24($fp)

        slt     $2,$2,10

        beq     $2,$0,.L4

        nop

        lw      $2,24($fp)

        andi    $2,$2,0x00ff

        addiu   $2,$2,48

        andi    $2,$2,0x00ff

        seb     $3,$2

        ld      $2,0($fp)

        daddu   $2,$fp,$2

        sb      $3,32($2)

        ld      $2,0($fp)

        daddiu  $2,$2,1

        sd      $2,0($fp)

        b       .L5

        nop

.L4:

        lw      $2,24($fp)

        andi    $2,$2,0x00ff

        addiu   $2,$2,55

        andi    $2,$2,0x00ff

        seb     $3,$2

        ld      $2,0($fp)

        daddu   $2,$fp,$2

        sb      $3,32($2)

        ld      $2,0($fp)

        daddiu  $2,$2,1

        sd      $2,0($fp)

.L5:

        ld      $2,1040($fp)

        bgez    $2,.L6

        nop

        daddiu  $2,$2,15

.L6:

        dsra    $2,$2,4

        sd      $2,1040($fp)

        b       .L7

        nop

.L2:

        ld      $2,%got_page(.LC0)($28)

        daddiu  $5,$2,%got_ofst(.LC0)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        lw      $2,4($fp)

        li      $3,16                 # 0x10

        subu    $2,$3,$2

        sw      $2,8($fp)

.L9:

        lw      $2,8($fp)

        blez    $2,.L8

        nop

        move    $5,$0

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZNSolsEi)($28)

        move    $25,$2

        nop

        lw      $2,8($fp)

        addiu   $2,$2,-1

        sw      $2,8($fp)

        b       .L9

        nop

.L8:

        ld      $2,0($fp)

        daddiu  $2,$2,-1

        sd      $2,16($fp)

.L12:

        ld      $2,16($fp)

        bltz    $2,.L13

        nop

        ld      $2,16($fp)

        daddu   $2,$fp,$2

        lb      $2,32($2)

        move    $5,$2

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c)($28)

        move    $25,$2

        nop

        ld      $2,0($fp)

        daddiu  $3,$2,-1

        ld      $2,16($fp)

        bne     $3,$2,.L11

        nop

        ld      $2,%got_page(.LC1)($28)

        daddiu  $5,$2,%got_ofst(.LC1)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

.L11:

        ld      $2,16($fp)

        daddiu  $2,$2,-1

        sd      $2,16($fp)

        b       .L12

        nop

.L13:

        nop

        move    $sp,$fp

        ld      $31,1080($sp)

        ld      $fp,1072($sp)

        ld      $28,1064($sp)

        daddiu  $sp,$sp,1088

        j       $31

        nop

hextodec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >):

        daddiu  $sp,$sp,-80

        sd      $31,72($sp)

        sd      $fp,64($sp)

        sd      $28,56($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(hextodec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(hextodec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))))

        sd      $4,32($fp)

        ld      $4,32($fp)

        ld      $2,%call16(_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv)($28)

        move    $25,$2

        nop

        sd      $2,24($fp)

        li      $2,1                        # 0x1

        sd      $2,0($fp)

        sd      $0,8($fp)

        lw      $2,28($fp)

        addiu   $2,$2,-1

        sw      $2,16($fp)

.L22:

        lw      $2,16($fp)

        bltz    $2,.L15

        nop

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        slt     $2,$2,48

        bne     $2,$0,.L16

        nop

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        slt     $2,$2,58

        beq     $2,$0,.L16

        nop

        li      $2,1                        # 0x1

        b       .L17

        nop

.L16:

        move    $2,$0

.L17:

        beq     $2,$0,.L18

        nop

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        addiu   $2,$2,-48

        move    $3,$2

        ld      $2,0($fp)

        dmult   $3,$2

        ld      $2,8($fp)

        mflo    $3

        daddu   $2,$2,$3

        sd      $2,8($fp)

        ld      $2,0($fp)

        dsll    $2,$2,4

        sd      $2,0($fp)

        b       .L19

        nop

.L18:

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        slt     $2,$2,65

        bne     $2,$0,.L20

        nop

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        slt     $2,$2,71

        beq     $2,$0,.L20

        nop

        li      $2,1                        # 0x1

        b       .L21

        nop

.L20:

        move    $2,$0

.L21:

        beq     $2,$0,.L19

        nop

        lw      $2,16($fp)

        move    $5,$2

        ld      $4,32($fp)

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)

        move    $25,$2

        nop

        lb      $2,0($2)

        addiu   $2,$2,-55

        move    $3,$2

        ld      $2,0($fp)

        dmult   $3,$2

        ld      $2,8($fp)

        mflo    $3

        daddu   $2,$2,$3

        sd      $2,8($fp)

        ld      $2,0($fp)

        dsll    $2,$2,4

        sd      $2,0($fp)

.L19:

        lw      $2,16($fp)

        addiu   $2,$2,-1

        sw      $2,16($fp)

        b       .L22

        nop

.L15:

        ld      $2,8($fp)

        move    $sp,$fp

        ld      $31,72($sp)

        ld      $fp,64($sp)

        ld      $28,56($sp)

        daddiu  $sp,$sp,80

        j       $31

        nop

.LC2:

        .ascii  "Hex value ? \000"

main:

        daddiu  $sp,$sp,-256

        sd      $31,248($sp)

        sd      $fp,240($sp)

        sd      $28,232($sp)

        sd      $18,224($sp)

        sd      $17,216($sp)

        sd      $16,208($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))

        daddiu  $17,$fp,48

        li      $16,3                 # 0x3

        move    $18,$17

.L26:

        li      $2,-1                 # 0xffffffffffffffff

        beq     $16,$2,.L25

        nop

        move    $4,$18

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev)($28)

        move    $25,$2

        nop

        daddiu  $18,$18,32

        daddiu  $16,$16,-1

        b       .L26

        nop

.L25:

        sw      $0,0($fp)

.L28:

        lw      $2,0($fp)

        slt     $2,$2,4

        beq     $2,$0,.L27

        nop

        ld      $2,%got_page(.LC2)($28)

        daddiu  $5,$2,%got_ofst(.LC2)

        ld      $4,%got_disp(_ZSt4cout)($28)

        ld      $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc)($28)

        move    $25,$2

        nop

        daddiu  $3,$fp,48

        lw      $2,0($fp)

        dsll    $2,$2,5

        daddu   $2,$3,$2

        move    $5,$2

        ld      $4,%got_disp(_ZSt3cin)($28)

        ld      $2,%call16(_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)

        move    $25,$2

        nop

        daddiu  $3,$fp,48

        lw      $2,0($fp)

        dsll    $2,$2,5

        daddu   $3,$3,$2

        daddiu  $2,$fp,16

        move    $5,$3

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,16

        move    $4,$2

        ld      $2,%got_disp(hextodec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))($28)

        move    $25,$2

        nop

        move    $3,$2

        lw      $2,0($fp)

        dsll    $2,$2,3

        daddu   $2,$fp,$2

        sd      $3,176($2)

        daddiu  $2,$fp,16

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

        b       .L28

        nop

.L27:

        ld      $3,176($fp)

        ld      $2,184($fp)

        dmult   $3,$2

        mflo    $2

        ld      $4,192($fp)

        ld      $3,200($fp)

        dmult   $4,$3

        mflo    $3

        daddu   $2,$2,$3

        sd      $2,8($fp)

        ld      $4,8($fp)

        ld      $2,%got_disp(dectohex(long long))($28)

        move    $25,$2

        nop

        move    $17,$0

        daddiu  $16,$fp,48

        daddiu  $16,$16,128

.L30:

        daddiu  $2,$fp,48

        beq     $16,$2,.L31

        nop

        daddiu  $16,$16,-32

        move    $4,$16

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        b       .L30

        nop

.L31:

        move    $2,$17

        b       .L42

        nop

        move    $18,$4

        beq     $17,$0,.L33

        nop

        li      $2,3                        # 0x3

        dsubu   $2,$2,$16

        dsll    $2,$2,5

        daddu   $16,$17,$2

.L34:

        beq     $16,$17,.L33

        nop

        daddiu  $16,$16,-32

        move    $4,$16

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        b       .L34

        nop

.L33:

        move    $2,$18

        move    $4,$2

        ld      $2,%call16(_Unwind_Resume)($28)

        move    $25,$2

        nop

        move    $16,$4

        daddiu  $2,$fp,16

        move    $4,$2

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        move    $17,$16

        b       .L36

        nop

        move    $17,$4

.L36:

        daddiu  $16,$fp,48

        daddiu  $16,$16,128

.L38:

        daddiu  $2,$fp,48

        beq     $16,$2,.L37

        nop

        daddiu  $16,$16,-32

        move    $4,$16

        ld      $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)

        move    $25,$2

        nop

        b       .L38

        nop

.L37:

        move    $2,$17

        move    $4,$2

        ld      $2,%call16(_Unwind_Resume)($28)

        move    $25,$2

        nop

.L42:

        move    $sp,$fp

        ld      $31,248($sp)

        ld      $fp,240($sp)

        ld      $28,232($sp)

        ld      $18,224($sp)

        ld      $17,216($sp)

        ld      $16,208($sp)

        daddiu  $sp,$sp,256

        j       $31

        nop

__static_initialization_and_destruction_0(int, int):

        daddiu  $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))

        move    $3,$4

        move    $2,$5

        sll     $3,$3,0

        sw      $3,0($fp)

        sll     $2,$2,0

        sw      $2,4($fp)

        lw      $3,0($fp)

        li      $2,1                        # 0x1

        bne     $3,$2,.L45

        nop

        lw      $3,4($fp)

        li      $2,65535                    # 0xffff

        bne     $3,$2,.L45

        nop

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $4,$2,%got_ofst(_ZStL8__ioinit)

        ld      $2,%call16(_ZNSt8ios_base4InitC1Ev)($28)

        move    $25,$2

        nop

        ld      $6,%got_disp(__dso_handle)($28)

        ld      $2,%got_page(_ZStL8__ioinit)($28)

        daddiu  $5,$2,%got_ofst(_ZStL8__ioinit)

        ld      $4,%got_disp(_ZNSt8ios_base4InitD1Ev)($28)

        ld      $2,%call16(__cxa_atexit)($28)

        move    $25,$2

        nop

.L45:

        nop

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu  $sp,$sp,48

        j       $31

        nop

_GLOBAL__sub_I_dectohex(long long):

        daddiu  $sp,$sp,-32

        sd      $31,24($sp)

        sd      $fp,16($sp)

        sd      $28,8($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_dectohex(long long))))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_dectohex(long long))))

        li      $5,65535                    # 0xffff

        li      $4,1                        # 0x1

        ld      $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)

        daddiu  $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))

        move    $25,$2

        nop

        move    $sp,$fp

        ld      $31,24($sp)

        ld      $fp,16($sp)

        ld      $28,8($sp)

        daddiu  $sp,$sp,32

        j       $31

        nop

IMAGE OF OUTPUT


Related Solutions

Write a program in C that takes as input a four-digit hexadecimal number and prints the...
Write a program in C that takes as input a four-digit hexadecimal number and prints the next 10 hexadecimal numbers. Define a hexadecimal number as int hexNum[4] Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70, 3C71, . . . .
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest common divisor. *I am using Eclipse DS-5 Community Workspace with A64 Instruction Set) Use the following algorithm: // Given two integers m and n: if (m < n) gcd(n, m) if n is a divisor of m gcd(m, n) = n else gcd (m, n) = gcd (n, m % n) Your program must be recursive. You must create a function that calls itself,...
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Write a program in C that takes as input an 8-bit binary number and prints the...
Write a program in C that takes as input an 8-bit binary number and prints the next 10 binary numbers. Define a binary number as int binNum[8]; Use binNum[0] to store the most significant (i.e., leftmost) bit and binNum[7] to store the least significant bit. Ask the user to input the first binary number with each bit separated by at least one space.
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly...
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction? 0x00156A33
Translate these two LEGv8 assembly instructions to 32-bit binary machine code. Give your answer in hexadecimal....
Translate these two LEGv8 assembly instructions to 32-bit binary machine code. Give your answer in hexadecimal. CBZ X19, exit ADD X10, X19, X20 exit:
1. Write an assembly language program that prompts the user for and reads four integers (x1,...
1. Write an assembly language program that prompts the user for and reads four integers (x1, y1, x2, y2) which represent the coordinates of two points. Make sure you keep track of which number is which. 2. Treat the line between the points as the radius of a sphere and compute the surface area of the sphere. Print the output with a label, such as “The surface area of the sphere is: …”. Hint: The distance between the points is...
Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit...
Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit representation as a 8-digit hexadecimal representation. For example: 2.5 decimal is 10.1 binary, which normalized is 1.01x21 and would be stored in the IEEE format as 0100 0000 0010 0000 0000 0000 0000 0000 which is 0x40200000
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT