Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assembly Microprocessors session 3 ing. Ernst E. Mak MSc.

Similar presentations


Presentation on theme: "Assembly Microprocessors session 3 ing. Ernst E. Mak MSc."— Presentation transcript:

1 Assembly Microprocessors session 3 ing. Ernst E. Mak MSc

2 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

3 Load a Value into a Register LOAD, Mnemonic is ld syntax: ld destination, source destination: –register –memory –memory by index source –value –register –memory –memory by index As a result of a LOAD, the destination is overwritten by the source.

4 Examples ld a,12 lda,12h lda,b ld b,a lda,(0100h) lda,(HL) ld bc,01FEh ld(100),a ld(HL),a ld(HL),b ld(HL),01h

5 Addition ADDITION, Mnemonic is add syntax: add destination, source destination: –SPECIAL register source –value –register –memory by index as a result of an ADDition, the destination is overwritten by the sum of source and destination, source remains untouched

6 addition examples adda,5 adda,b adda,(HL) addHL,BC addHL,HL

7 Carry decimal addition: 861+152 8 6 1 1 5 2 + 1 0 1 3 11

8 Flags

9 Flags (2) SCH P/V NZ CARRY-FLAG NEGATIVE PARITY or OVERFLOW BCD half carry flag ZERO flag SIGN FLAG

10 Carry Flag It detects a carry from bit 7 into (the non- existent) bit 8, or in the case of register- pairs, from bit 15 into what would have been bit 16. It is also used by shift and rotate instructions, in which one bit is “lost” from a register and moves into the carry. This is probably the most frequently accessed flag of all.

11 addition with carry addition include the carry (bit); Mnemonic: adc, syntax similar to add Purpose: to calculate the effect of the carry into the next digit Effect: after for example: adc 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:=254+515 (= 254+(2*256+3)) ld b,2 ld c,3 ld a,254 add a,c ld l,a lda,0 adc a,b ld h,a

12 Zero Flag: It checks whether or not the last result was actually zero. If so the flag is set to 1, but otherwise it is reset. Watch out for this flag though – it can be very deceiving – many of the register-pair instructions simply do not change it as you’d expect: instructions like DEC or ADD for instance will only change the zero flag if applied to single registers.

13 Sign Flag: It stores the sign (positive or negative) of the last result. A positive number resets the flag to zero, and a negative number sets it to 1. For the purposes of this flag, zero is counted as positive. The value of the S flag is therefore always equal to the leftmost bit of the result. It may be tested using instructions like JP P (Jump if positive) or JP M (Jump if negative (Minus)).

14 Parity/Overflow Flag: It does two jobs at one. 1.The Parity of a result is either odd or even, depending on the number of 1’s in the result (in binary). If the parity is even, the flag is 1 (an odd number), if the parity is odd, the flag is 0 (an even number). Generally, the parity is involved at boolean operations 2.An Overflow represents an “accidental” change of sign of result – a carry from bit 6 into bit 7 effectively. Generally, this flag is involved at additions, subtractions, increases and decreases

15 Other Flags Subtract Flag: It is also called the N flag, it simply lets the machine know whether or not the last instruction was an addition, or a subtraction. You can’t get hold of this flag unless you make use of PUSH and POP. Half-Carry Flag: It sets if there is a carry from bit 3 into bit 4, or, in the case of register-pairs, from bit 11 into bit 12. It is used internally by the Z80 for such instructions as DAA, but can not be easily tested by the programmer.

16 WARNING WITH FLAGS Flags are changed in a rather limited fashion. Some instructions render one or more flags untouched, so they keep reflecting the state of an earlier instruction

17 Jumping Jump, Mnemonic is jp syntax: jp {condition,} destination conditions (optional) : C, NC carryflag Z, NZ zero flag M, P minus.positive PO,PE parity odd/even destination –memory location –label as a result of a JumP. the program commences at the destination of the jump.

18 COMPARE Compare, Mnemonic is cp syntax: cp reference reference –value –register –memory pointed by index The result of a ComPare is, that flags are set as if we would have substracted the referenced value from the A register. but the substraction is never performed


Download ppt "Assembly Microprocessors session 3 ing. Ernst E. Mak MSc."

Similar presentations


Ads by Google