Assembly Language for Beginners

(Jeff_L) #1

1.22. MANIPULATING SPECIFIC BIT(S)


These instructions are used for resetting (BTR), setting (BTS) and inverting (or complementing:BTC) spe-
cific bits. The 31st bit isMSB, counting from 0.


Finally, the result is copied intoXMM0, because floating point values are returned throughXMM0in Win64
environment.


MIPS


GCC 4.4.5 for MIPS does mostly the same:


Listing 1.284: Optimizing GCC 4.4.5 (IDA)

my_abs:
; move from coprocessor 1:
mfc1 $v1, $f12
li $v0, 0x7FFFFFFF
; $v0=0x7FFFFFFF
; do AND:
and $v0, $v1
; move to coprocessor 1:
mtc1 $v0, $f0
; return
jr $ra
or $at, $zero ; branch delay slot


set_sign:
; move from coprocessor 1:
mfc1 $v0, $f12
lui $v1, 0x8000
; $v1=0x80000000
; do OR:
or $v0, $v1, $v0
; move to coprocessor 1:
mtc1 $v0, $f0
; return
jr $ra
or $at, $zero ; branch delay slot


negate:
; move from coprocessor 1:
mfc1 $v0, $f12
lui $v1, 0x8000
; $v1=0x80000000
; do XOR:
xor $v0, $v1, $v0
; move to coprocessor 1:
mtc1 $v0, $f0
; return
jr $ra
or $at, $zero ; branch delay slot


One singleLUIinstruction is used to load 0x80000000 into a register, becauseLUIis clearing the low 16
bits and these are zeros in the constant, so oneLUIwithout subsequentORIis enough.


ARM


Optimizing Keil 6/2013 (ARM mode)


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

my_abs PROC
; clear bit:
BIC r0,r0,#0x80000000
BX lr
ENDP


set_sign PROC

Free download pdf