In: Computer Science
- 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
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