Back to Assembly lang name operation START MOV
Back to Assembly lang
name operation START: MOV operand(s) CX, 5 ; ; comment ; ������� ! ‘ ’ ��� !
name operation operand(s) • Okay letters, digits, ? , . , @, _, $, % • Illegal names – - If any blanks – aaa If begin with a digit – 2 asad If ‘. ’ not first char. – aq. 12 If has illegal char – aa&bb ; comment
name operation operand(s) ; comment • For an Instruction: Symbolic operation code [opcode]: Assembler translates these codes into Machine lang opcode. MOV, ADD, SUB, … • For an Directive: pseudo-operation code – pseudo-op, do not translate PROC is used to create a procedure
name operation operand(s) ; comment • An instruction may have 0/1/2 operands e. g. , NOP ; no operands – does nothing INC AX ; 1 op. – adds 1 to contents of AX ADD destination, source
4. 2 Program data • Binary – 1011 b, 1100 B • Decimal – 10111, 10111 d, -3419 D 1, 23 – x • Hex – start with a decimal digit, ends with ‘H’ – 3 BA 3 H, 0 FFFFH • Characters – within ‘aa’ or “aa”
Pseudo-ops • • • DB – define data BYTE DW – word DD – doubleword – two consecutive words DQ – quadword – 4 … DT – tenbytes – 10…
4. 3 Variables e. g. , ALPHA AA name operation operand(s) ; comment name DB initial value ; -128 ~ 127; or 0 -255 DB 4 DB ; variable ALPHA=4 ? ; uninitialized byte
4. 3. 3 Array Ekta. Array Symbol Ekta. Array+1 Ekta. Array+2 DB 10 H, 22 H Address 200 h Contents 10 H 201 h 202 h 20 H 22 H
For DW – 2 bytes Symbol Ekta. Array+2 Ekta. Array+4 Address 200 h Contents 10 H 202 h 204 h 20 H 22 H
WORD 1 DW 1234 H ; low Byte of WORD 1 contains 34 H ; high Byte of WORD 1 contains 12 H
4. 5 basic instructions • MOV – move; contents of destination is replaced by the contents of source • XCHG – exchange; swapping Q: exa? ?
• ADD W 1, AX ; W 1 = W 1 + AX ; W 1 – changes with added/sum value ; AX – unchanged • SUB AX, DX ; Subtract DX from AX ; New value in AX – AX changes ; DX unchanged
Direct ADD/SUB between memory locations WRONG! • ADD W 1, W 2 ; wrong as direct memory location Source Gen Reg. Memory Loc. Constant Destination General Reg. Yes Yes Memory loc. Yes NO Yes
INC Increment • INC destination W 1 ; e. g. , W 1=0003 Before After INC, W 1=0003 W 1=? ? 0004
DEC Decrement • DEC destination W 1 ; e. g. , W 1=FFFF Before After INC, W 1=FFFF W 1=? ? FFFE
NEG negate the contents of destination • NEG destination ; reg. / mem. ; replace the contents by it’s two’s complement NEG Before After NEG, W 1 ; e. g. , W 1=0002 W 1=? ? FFFE
• Note: - Both types MUST be the same type e. g. , MOV AH, ‘A’ ; what is in AH? ; ‘A’ = 41 H MOV AX, ‘A’ ; what is in AX? 0041 H
Do! High- to Assembly 1. B = A 2. A = 5 – A 3. A = B – 2 x A
1. B = A • MOV AX, A B, AX • A direct mem-to-mem move is illegal
2. A = 5 - A • MOV • SUB • MOV AX, 5 AX, A A, AX • NEG • ADD A A, 5
3. A = B – 2 x. A • MOV • SUB AX, B ; AX = B AX, A; AX=B-A – A ; AX = B – 2 A • MOV A, AX; A = AX = B – 2 A
- Slides: 22