SlideShare a Scribd company logo
1 of 12
Download to read offline
Lecture 06
Programming The 8086 In
AAiT
Programming The 8086 In
Assembly Language
…Continued
Daniel D.Daniel D.Daniel D.Daniel D. DECEECEgECEgECEgECEg ---- 4501450145014501
Assembler directives & operators
Issues AAiT
program examples & exercises
1ECEgECEgECEgECEg ---- 4501450145014501
Assembler directives (Preprocessors)
ASSUME tell the assembler the name of the logical segment it
should use for a specified segment.
e.g. ASUME CS: code
DB (define byte) Used to declare byte type variable(s) and set aside
storage for it
e.g. High_scores DB 82H, 78H, 75H
AAiT
e.g. High_scores DB 82H, 78H, 75H
Name DB “ZELALEM”
Also, DW, DD, DQ, DT
END end of program. Assembler ignores any instruction after END
EQU (equate) Used to give a name to some value or symbol.
e.g. Ratio EQU 05h
Henceforth, Ratio can be used instead of 05h in the program
2ECEgECEgECEgECEg ---- 4501450145014501
Processor directives
EVEN tell the assembler to align the data or instruction to the even
bank.
EXTRN Used to tell the assembler that the names or labels following
the directive are in some other assembly module.
GLOBAL can be used in place of PUBLIC or EXTRN directives. It is used
to make the symbol available to other modules.
INCLUDE Include Source Code from File
AAiT
INCLUDE Include Source Code from File
e.g. INCLUDE “program_2.asm”
LENGTH Is an operator, which tells the assembler to determine the
number of elements in some named data item, such as a
string or an array.
e.g. MOV CX, LENGTH string1 CX = no of elements in string1
3ECEgECEgECEgECEg ---- 4501450145014501
Processor directives
NAME Used to give a specific name to each assembly module
when programs consisting of several modules are written.
e.g. NAME “Main”
OFFSET Is an operator which tells the assembler to determine the
offset or the displacement of a named data item (variable) or
procedure from start of the segment which contains it.
e.g. MOV BX, OFFSET TABLE
AAiT
e.g. MOV BX, OFFSET TABLE
ORG allows to set the location counter to a desired value at any
point in the program.
e.g. ORG 100H set the location counter to 0100H
ORG $ +100 Reserve the next 100 bytes
NB: Refer to the handout for other directives
4ECEgECEgECEgECEg ---- 4501450145014501
Program Examples
E.g. 1
Determine the contents of the GP registers and flags after these
programs.
MOV AX,1234H V DB 5, 8, 12, 1
MOV BX,5678H MOV AL, 0
PUSH AX MOV BX, 0
PUSH BX MOV DL, 24
ORG 40H
JMP START
NAME DB “Abebe”
START:
MOV SI, OFFSET NAME
AAiT
PUSH BX MOV DL, 24
POP AX DO: ADD AL, V[BX]
POP BX INC BX
CMP AL, DL
JLE DO
AX ? AL ? DL ? BX ?
BX ? ZF ? CF ? PF ? IP? AL? CX? [SI]? ZF?
MOV SI, OFFSET NAME
INC SI
LOADS [SI]
MOV CX, 05H
REPEAT: INC SI
CMP AL, [SI]
LOOPE REPEAT
5ECEgECEgECEgECEg ---- 4501450145014501
Program Examples
E.g. 2
1. Write a program that takes temperature values in Celsius
from the keyboard; changes to Fahrenheit; and displays
the result on the screen, like:
20 C = 68 F
or 05 C = 41 F
AAiT
or 05 C = 41 F
take input range 00-99 c
Use INT 21h/ah = 1……………for input function
Use INT 21h/ah = 2……………for character display
TF = 9/5 Tc + 32
6ECEgECEgECEgECEg ---- 4501450145014501
E.g. 2 solution
The input sub-program
name “input”
org 100h ;locate code starting here
jmp start
input db 0,0 ;reserve memory for i/p
AAiT
input db 0,0 ;reserve memory for i/p
output db 0,0,0 ;and for o/p
;take a two digit no and save @input
start:
lea bx, input ;points to 1st input variable
mov si, bx ;keep the input address
mov cx, 2 ;no of chars.
mov ah, 1 ;for input function
INP:
int 21h ;input function
mov [bx], al ;save the i/p
inc bx
loop INP
Next slide
7ECEgECEgECEgECEg ---- 4501450145014501
E.g. 2 solution….cnt’d
The conversion sub-program
name “conversion”
;form a single no from the inputs
mov dl, 10
mov al, [si] ;fist digit
and al, 0Fh ;change to decimal
;convert to Fahrenheit
mov dl, 5
div dl ;divide by 5
AAiT
and al, 0Fh ;change to decimal
mul dl ;10’s decimal place
inc si
mov dl, [si] ;second digit
and dl, 0Fh ;change to decimal
add al, dl ;one’s decimal place
div dl ;divide by 5
mov dl, 9
mul dl ;multiply by 9
add al, 32 ;add 32
Next slide
8ECEgECEgECEgECEg ---- 4501450145014501
E.g. 2 solution….cnt’d
The formatting sub-program (to ASCII)
name “format”
; change result to ASCII & store @output
mov cx, 3
lea bx, output ;point in memory @output
add bx, 2 ;start at one’s decimal place
mov di, bx ;keep the o/p address
ascii:
mov ah, 0
cmp al, 10
jb done
div dl ;ax/10: q=al, r=ah
or ah, 30h ;convert to ASCII
AAiT
mov di, bx ;keep the o/p address
mov dl, 10
or ah, 30h ;convert to ASCII
mov [bx], ah
dec bx
loop ascii
done: or al, 30h ;one’s place
mov [bx], al
NB: Character input and output is implemented in ASCII format,
that’s why we need to convert ASCII to decimal at input and
decimal to ASCII at output.
Next slide
9ECEgECEgECEgECEg ---- 4501450145014501
E.g. 2 solution….cnt’d
The display sub-program
; display the result in the
; required format
name “display”
mov cx, 2
mov ah, 2
lea si, input
mov cx,3 ;display output
op: cmp bx, di
ja finish
mov dl,[bx]
AAiT
lea si, input
ip: mov dl, [si] ;display input
int 21h
inc si
loop ip
mov dl, 'C' ;display C
int 21h
mov dl, ' = ' ;display =
int 21h
mov dl,[bx]
int 21h
inc bx
loop op
finish: mov dl,'F‘ ;display F
int 21h
ret ;return to operating system
10ECEgECEgECEgECEg ---- 4501450145014501
Exercise:
2. Consider a login system. Suppose you have a 5-character
password stored in DS in memory. Write a program that
reads a 5-char password string from the keyboard port;
compare the string with the password in memory; prints
“access granted” if correct or “access denied” otherwise.
AAiT
“access granted” if correct or “access denied” otherwise.
Use INT 21h/ah = 1…………for input function
Use INT 21h/ah = 9…………to display a string
Use CMPSB to compare strings
11ECEgECEgECEgECEg ---- 4501450145014501

More Related Content

What's hot

Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programmingKartik Sharma
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructionswarda aziz
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programmingKartik Sharma
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
8086 Microprocessor Instruction set
8086 Microprocessor Instruction set8086 Microprocessor Instruction set
8086 Microprocessor Instruction setVijay Kumar
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086University of Gujrat, Pakistan
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 

What's hot (20)

Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programming
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
 
[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programming
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
8086 Microprocessor Instruction set
8086 Microprocessor Instruction set8086 Microprocessor Instruction set
8086 Microprocessor Instruction set
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 
Instruction set
Instruction setInstruction set
Instruction set
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 

Similar to 8086 Assembly Programming Lecture

Similar to 8086 Assembly Programming Lecture (20)

Lecture5
Lecture5Lecture5
Lecture5
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
8085 instruction set
8085 instruction set8085 instruction set
8085 instruction set
 
Keyboard interrupt
Keyboard interruptKeyboard interrupt
Keyboard interrupt
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Lec06
Lec06Lec06
Lec06
 
Alp 05
Alp 05Alp 05
Alp 05
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computer
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Debug(1).ppt
Debug(1).pptDebug(1).ppt
Debug(1).ppt
 
Assembly Language Compiler Implementation
Assembly Language Compiler ImplementationAssembly Language Compiler Implementation
Assembly Language Compiler Implementation
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
 
implementation of data instrucions in emu8086
implementation of data instrucions in emu8086implementation of data instrucions in emu8086
implementation of data instrucions in emu8086
 

More from misgina Mengesha (15)

Lecture9
Lecture9Lecture9
Lecture9
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture2
Lecture2Lecture2
Lecture2
 
Lecture1
Lecture1Lecture1
Lecture1
 
Sprabq8
Sprabq8Sprabq8
Sprabq8
 
Sensors2006
Sensors2006Sensors2006
Sensors2006
 
Sensors31
Sensors31Sensors31
Sensors31
 
Sensing for robotics and control s set13
Sensing for robotics and control s set13Sensing for robotics and control s set13
Sensing for robotics and control s set13
 
Introduction to sensors
Introduction to sensorsIntroduction to sensors
Introduction to sensors
 
Cn3 sensors and transducers-12
Cn3 sensors and transducers-12Cn3 sensors and transducers-12
Cn3 sensors and transducers-12
 
Cn3 sensors and transducers-1
Cn3 sensors and transducers-1Cn3 sensors and transducers-1
Cn3 sensors and transducers-1
 
480 sensors
480 sensors480 sensors
480 sensors
 
Wwwwww
WwwwwwWwwwww
Wwwwww
 

8086 Assembly Programming Lecture

  • 1. Lecture 06 Programming The 8086 In AAiT Programming The 8086 In Assembly Language …Continued Daniel D.Daniel D.Daniel D.Daniel D. DECEECEgECEgECEgECEg ---- 4501450145014501
  • 2. Assembler directives & operators Issues AAiT program examples & exercises 1ECEgECEgECEgECEg ---- 4501450145014501
  • 3. Assembler directives (Preprocessors) ASSUME tell the assembler the name of the logical segment it should use for a specified segment. e.g. ASUME CS: code DB (define byte) Used to declare byte type variable(s) and set aside storage for it e.g. High_scores DB 82H, 78H, 75H AAiT e.g. High_scores DB 82H, 78H, 75H Name DB “ZELALEM” Also, DW, DD, DQ, DT END end of program. Assembler ignores any instruction after END EQU (equate) Used to give a name to some value or symbol. e.g. Ratio EQU 05h Henceforth, Ratio can be used instead of 05h in the program 2ECEgECEgECEgECEg ---- 4501450145014501
  • 4. Processor directives EVEN tell the assembler to align the data or instruction to the even bank. EXTRN Used to tell the assembler that the names or labels following the directive are in some other assembly module. GLOBAL can be used in place of PUBLIC or EXTRN directives. It is used to make the symbol available to other modules. INCLUDE Include Source Code from File AAiT INCLUDE Include Source Code from File e.g. INCLUDE “program_2.asm” LENGTH Is an operator, which tells the assembler to determine the number of elements in some named data item, such as a string or an array. e.g. MOV CX, LENGTH string1 CX = no of elements in string1 3ECEgECEgECEgECEg ---- 4501450145014501
  • 5. Processor directives NAME Used to give a specific name to each assembly module when programs consisting of several modules are written. e.g. NAME “Main” OFFSET Is an operator which tells the assembler to determine the offset or the displacement of a named data item (variable) or procedure from start of the segment which contains it. e.g. MOV BX, OFFSET TABLE AAiT e.g. MOV BX, OFFSET TABLE ORG allows to set the location counter to a desired value at any point in the program. e.g. ORG 100H set the location counter to 0100H ORG $ +100 Reserve the next 100 bytes NB: Refer to the handout for other directives 4ECEgECEgECEgECEg ---- 4501450145014501
  • 6. Program Examples E.g. 1 Determine the contents of the GP registers and flags after these programs. MOV AX,1234H V DB 5, 8, 12, 1 MOV BX,5678H MOV AL, 0 PUSH AX MOV BX, 0 PUSH BX MOV DL, 24 ORG 40H JMP START NAME DB “Abebe” START: MOV SI, OFFSET NAME AAiT PUSH BX MOV DL, 24 POP AX DO: ADD AL, V[BX] POP BX INC BX CMP AL, DL JLE DO AX ? AL ? DL ? BX ? BX ? ZF ? CF ? PF ? IP? AL? CX? [SI]? ZF? MOV SI, OFFSET NAME INC SI LOADS [SI] MOV CX, 05H REPEAT: INC SI CMP AL, [SI] LOOPE REPEAT 5ECEgECEgECEgECEg ---- 4501450145014501
  • 7. Program Examples E.g. 2 1. Write a program that takes temperature values in Celsius from the keyboard; changes to Fahrenheit; and displays the result on the screen, like: 20 C = 68 F or 05 C = 41 F AAiT or 05 C = 41 F take input range 00-99 c Use INT 21h/ah = 1……………for input function Use INT 21h/ah = 2……………for character display TF = 9/5 Tc + 32 6ECEgECEgECEgECEg ---- 4501450145014501
  • 8. E.g. 2 solution The input sub-program name “input” org 100h ;locate code starting here jmp start input db 0,0 ;reserve memory for i/p AAiT input db 0,0 ;reserve memory for i/p output db 0,0,0 ;and for o/p ;take a two digit no and save @input start: lea bx, input ;points to 1st input variable mov si, bx ;keep the input address mov cx, 2 ;no of chars. mov ah, 1 ;for input function INP: int 21h ;input function mov [bx], al ;save the i/p inc bx loop INP Next slide 7ECEgECEgECEgECEg ---- 4501450145014501
  • 9. E.g. 2 solution….cnt’d The conversion sub-program name “conversion” ;form a single no from the inputs mov dl, 10 mov al, [si] ;fist digit and al, 0Fh ;change to decimal ;convert to Fahrenheit mov dl, 5 div dl ;divide by 5 AAiT and al, 0Fh ;change to decimal mul dl ;10’s decimal place inc si mov dl, [si] ;second digit and dl, 0Fh ;change to decimal add al, dl ;one’s decimal place div dl ;divide by 5 mov dl, 9 mul dl ;multiply by 9 add al, 32 ;add 32 Next slide 8ECEgECEgECEgECEg ---- 4501450145014501
  • 10. E.g. 2 solution….cnt’d The formatting sub-program (to ASCII) name “format” ; change result to ASCII & store @output mov cx, 3 lea bx, output ;point in memory @output add bx, 2 ;start at one’s decimal place mov di, bx ;keep the o/p address ascii: mov ah, 0 cmp al, 10 jb done div dl ;ax/10: q=al, r=ah or ah, 30h ;convert to ASCII AAiT mov di, bx ;keep the o/p address mov dl, 10 or ah, 30h ;convert to ASCII mov [bx], ah dec bx loop ascii done: or al, 30h ;one’s place mov [bx], al NB: Character input and output is implemented in ASCII format, that’s why we need to convert ASCII to decimal at input and decimal to ASCII at output. Next slide 9ECEgECEgECEgECEg ---- 4501450145014501
  • 11. E.g. 2 solution….cnt’d The display sub-program ; display the result in the ; required format name “display” mov cx, 2 mov ah, 2 lea si, input mov cx,3 ;display output op: cmp bx, di ja finish mov dl,[bx] AAiT lea si, input ip: mov dl, [si] ;display input int 21h inc si loop ip mov dl, 'C' ;display C int 21h mov dl, ' = ' ;display = int 21h mov dl,[bx] int 21h inc bx loop op finish: mov dl,'F‘ ;display F int 21h ret ;return to operating system 10ECEgECEgECEgECEg ---- 4501450145014501
  • 12. Exercise: 2. Consider a login system. Suppose you have a 5-character password stored in DS in memory. Write a program that reads a 5-char password string from the keyboard port; compare the string with the password in memory; prints “access granted” if correct or “access denied” otherwise. AAiT “access granted” if correct or “access denied” otherwise. Use INT 21h/ah = 1…………for input function Use INT 21h/ah = 9…………to display a string Use CMPSB to compare strings 11ECEgECEgECEgECEg ---- 4501450145014501