Docsity

Microprocessors: Arithmetic Instructions - SUB and SBC, Study notes of Microprocessors

Partial preview of the text

Download Microprocessors: Arithmetic Instructions - SUB and SBC and more Study notes Microprocessors in PDF only on Docsity!

EEE304 MICROPROCESSORS

5. Week

Arithmetic Instructions โ€“ SUB

Arithmetic Instructions โ€“ SBC

Arithmetic Instructions โ€“ SBC

  • SBC subtracts operand 2 from operand 1 with the carry flag, placing the result in Rd - It uses a carry bit, so can subtract numbers larger than 32 bits. - Use S suffix to update conditional field

<64-bit Subtraction>

64 bit 1 st^ operand: R5 and R 64 bit 2 nd^ operand: R9 and R 64 bit result: R1 and R

SUBS R0, R4, R8 ; R0 = R4 โ€“ R SBC R1, R5, R9 ; R1 = R5 โ€“ R9 - !(carry flag) (^5)

Examples

Before: cpsr^ = nzcv r1 = 0x0000_ SUBS r1, r1, #

After: cpsr^ = n ZC v r1 = 0x0000_

  • Why is the C flag set (C = 1)?

Logical Instructions

ALU

Rn

BarrelShifter

Rm

Rd

N AND^

logical bitwise AND of two 32-bit values

Rd = Rn & N

ORR

logical bitwise OR of two 32-bit values

Rd = Rn | N

EOR

logical exclusive OR of two 32-bit values

Rd = Rn ^ N

BIC logical bit clear Rd = Rn & ~N

Syntax: {cond}{S} Rd, Rn, N

Logical Instructions โ€“ AND

  • AND performs a logical AND between the two operands, placing the result in Rd - It is useful for masking the bits

AND R0, R0,

; Keep bits zero and one of R0 and discard the rest