10
Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Embed Size (px)

Citation preview

Page 1: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Assembly Microprocessorssession 4

ing. Ernst E. Mak MSc

Page 2: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Generic Instructions Taxonomy

• input/output data• load a value(register) into a register• arithmetic• jumping / subroutine• control• bitwise operators : Boolean, Register shifts • interrupt handling• stacking

Page 3: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Subtract

• SUBTRACT, Mnemonic is SUB• syntax: SUB source

• destination (not shown):

– A register

• source– value– register– memory by index

As a result of a SUBtract, the destination is overwritten by the accumulator (a-register) minus the source.

Page 4: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

subtraction examples

• SUB B

• SUB C

• SUB 15h

• SUB (HL)

Page 5: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

BORROW

• decimal subtraction: 861-162

8 6 11 6 2

-

6 9 9

1010

Page 6: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

subtraction with carry• subtraction include the carry(bit);• Mnemonic: sbc, syntax sbc a, source or sbc HL,source2

• Purpose: to calculate the effect of the carry while subtracting

SOURCE:single register a,b,c,d,e

if sbc a,...

double register HL,DE,BC

if sbc HL,...

Effect:

after for example: sbc a,b the a register will be:

a:=a-b-1 if the carry was set

a:=a-b if the carry was reset

Example: HL:=515-245 (= (2*256+3)-245)

ld hl,515d

ld c,245

ld a,l

sub c

ld e,a

ld a,h

sbc a,0

ld d,a

halt

Page 7: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Increment• increment, Mnemonic is inc• syntax: inc destination

• destination:– register– memory by index

as a result of an INCrement, the destination is increased by 1flags are set and reset accordingly, EXCEPT the CARRY

Page 8: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

Decrement• increment, Mnemonic is dec• syntax: dec destination

• destination:– register– memory by index

as a result of an DECrement, the destination is decreased by 1

flags are set and reset accordingly , EXCEPT the CARRY

Page 9: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

LOOPING

• backward loop init: ld a,2

label: inc a

cp 150d

jp nz,label

halt

Page 10: Assembly Microprocessors session 4 ing. Ernst E. Mak MSc

LOOPING

• forward loop init: ld a,2

label: cp 0C3h

jp z,end

inc a

jp label

end: halt