Micro Processors Lab Demo: T. Krishna Chaitanya
Micro Processors Lab Demo: T. Krishna Chaitanya
T. Krishna Chaitanya
Assembly Language Today
Assembly Language is a low level programming language
A program written directly in assembly language has the
potential to be smaller and to run faster than a HLL program
8086 CPU has 8 general purpose registers, each register has its own name:
These fields are separated by White Space (tab, blank, \n, etc.)
8086 Instruction - Example
Label - INIT:
Operator - mov
Operands - ax and bx
Comment - alphanumeric string between ; and \n
Stack
– For dynamic data storage
– Source file defines size
– Must have exactly 1
Data
– For static data Storage
– Source file defines size
– Source file defines content (optional)
– Can have 0 or more
Code
– For machine Instructions
– Must have 1 or more
x86 Instruction Type Classifications
DATA TRANSFER
– General mov ax, [DAT1] ;ax gets contents of mem
– Strings cmpsb ;if DS:SI=ES:DI then ZF=1
– Special Purpose xchg ax, bx ;ax gets bx and bx gets ax
ARITHMETIC/LOGIC
– Integer add ax, bx ;ax gets ax+bx
– ASCII, BCD aaa ;changes ASCII # to int.
– Floating Point fadd DAT ;ST get ST+DAT
– Logical and ax, bx ;ax gets ax AND bx
– Shifting ror ax, 2 ;ax contents shifted-2 right
CONTROL TRANSFER
– Branching jnz LABEL1 ;if ZF=1 then IP=LABEL1
– Interrupt int 21h ;invoke INT handler 21h
– Subroutine call SUB1 ;invoke subroutine, SUB1
– Modify Flag cli ;IF gets zero
– Halt Processor hlt ;need RESET to run again
– No Operation nop ;
Data Transfer Instructions
db define byte
dw define word (2 bytes)
dd define double word (4 bytes)
dq define quadword (8 bytes)
dt define tenbytes
equ equate, assign numeric expression to a name
Examples:
db 100 dup (?) define 100 bytes, with no initial values for bytes
db “Hello” define 5 bytes, ASCII equivalent of “Hello”.
Sample MOV Instructions
code segment
assume cs:code, ds:data
code ends
end start
data segment
n dw 5
res dw ?
data ends
code segment
assume cs:code,ds:data
mov ax,data
mov ds,ax
mov ax,n
sub ax,1
mov bx,ax
add ax,1
yy: mul bx
dec bx
jz down
loop yy
down:mov res,ax
mov ax,4c00h
int 21h
code ends
end
Write programme on the screen
Next step is to create executable file using the linker:
This causes linker to create: ADD.EXE
Write programme on the screen
Press F 7
Press F 7
Press F 7
Press F 7
Press F 7
Press F 7
;add two 8-bit numbers
data segment
addend db 20h
adder db 10h
sum db ?
data ends
code segment
assume cs:code, ds:data
code ends
end start
data segment
n dw 5
res dw ?
data ends
code segment
assume cs:code,ds:data
mov ax,data
mov ds,ax
mov ax,n
sub ax,1
mov bx,ax
add ax,1
yy: mul bx
dec bx
jz down
loop yy
down:mov res,ax
mov ax,4c00h
int 21h
code ends
end