Assembly Language for Beginners

(Jeff_L) #1

1.28. 64-BIT VALUES IN 32-BIT ENVIRONMENT


Keil for ARM mode, on the other hand, is able to produce 64-bit multiplication code:


Listing 1.380: Optimizing Keil 6/2013 (ARM mode)

||f_mul|| PROC
PUSH {r4,lr}
UMULL r12,r4,r0,r2
MLA r1,r2,r1,r4
MLA r1,r0,r3,r1
MOV r0,r12
POP {r4,pc}
ENDP


||f_div|| PROC
PUSH {r4,lr}
BL __aeabi_uldivmod
POP {r4,pc}
ENDP


||f_rem|| PROC
PUSH {r4,lr}
BL __aeabi_uldivmod
MOV r0,r2
MOV r1,r3
POP {r4,pc}
ENDP


MIPS


Optimizing GCC for MIPS can generate 64-bit multiplication code, but has to call a library routine for 64-bit
division:


Listing 1.381: Optimizing GCC 4.4.5 (IDA)

f_mul:
mult $a2, $a1
mflo $v0
or $at, $zero ; NOP
or $at, $zero ; NOP
mult $a0, $a3
mflo $a0
addu $v0, $a0
or $at, $zero ; NOP
multu $a3, $a1
mfhi $a2
mflo $v1
jr $ra
addu $v0, $a2


f_div:


var_10 = -0x10
var_4 = -4


lui $gp, (__gnu_local_gp >> 16)
addiu $sp, -0x20
la $gp, (__gnu_local_gp & 0xFFFF)
sw $ra, 0x20+var_4($sp)
sw $gp, 0x20+var_10($sp)
lw $t9, (__udivdi3 & 0xFFFF)($gp)
or $at, $zero
jalr $t9
or $at, $zero
lw $ra, 0x20+var_4($sp)
or $at, $zero
jr $ra
addiu $sp, 0x20

f_rem:

Free download pdf