Lecture 02 Introduction To Assembly Language
Lecture 02 Introduction To Assembly Language
to Assembly Language
Introduction to assembly language
An example of an instruction is
start: MOV CX,5 ;initialize counter
An example of an assembler directive is
MAIN PROC
Instruction
Operand 1
Operand 2
Comment
Example
MOV DX,AX ;register-to-register
MOV data1,DH ;register-to-memory, direct
MOV [DI],BX ;register-to-memory, indirect
MOV CX,40 ;immediate-to-register
MOV data1,40 ;immediate-to-memory
MOV CH,data1 ;memory-to-register
MOV AL, 0FFh ; Hex. Number move
MOV AH, 255 ; Dec. Number move
MOV DL, 01011111b; Binary Number move
MOV BL, AH ; Register value move
MOV CL, ‘A’ ; set CL to ASCII code of 'A', it is 41h.
Destination Operand
Source Operand
General Register Memory Location
General Register Yes Yes
Memory Location yes no
Example
WORDQ DW ?
……
XCHG CL,BH ; exchange the contents two
; registers
XCHG CX,WORDQ ; exchange the contents register
; and memory
24 Dr. Hassanein Shaban Ahmed
Sample assembly Programs
.model small
.stack 64
.DATA
data1 DB 52h
data2 DB 29h
sum DB ?
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AL,data1
MOV BL,data2
ADD AL,BL
MOV sum,AL
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
.MODEL SMALL
.STACK 64
.DATA
xx1 Dw 0AFh
yy1 Dw 96h
zz1 Dw ?
.CODE
MAIN PROC FAR
mov ax,@data
mov ds,ax
mov ax,xx1
add ax,yy1
mov zz1,ax
mov ax,4c00h
int 21h
MAIN ENDP
END MAIN
Ex4.4
.MODEL SMALL
.STACK 64
.DATA
xx1 Dw 0FFFEh
.CODE
MAIN PROC
mov ax,@data
mov ds,ax
mov ax,xx1
NEG ax
mov ah,4ch
int 21h
MAIN ENDP
END MAIN
31 Dr. Hassanein Shaban Ahmed