SlideShare a Scribd company logo
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

PPSX
8085 Interfacing with I/O Devices or Memory
PDF
8085 microprocessor Architecture and pin description
PPT
1326 Introduction To 8086 Microprocessor
DOCX
8086 pin diagram description
PDF
Performance Comparison Between x86 and ARM Assembly
PPT
Ch12 microprocessor interrupts
PDF
system software 16 marks
8085 Interfacing with I/O Devices or Memory
8085 microprocessor Architecture and pin description
1326 Introduction To 8086 Microprocessor
8086 pin diagram description
Performance Comparison Between x86 and ARM Assembly
Ch12 microprocessor interrupts
system software 16 marks

What's hot (20)

PPT
Assembly Language Lecture 4
PDF
Guia 3
PPTX
INTEL 8086 MICROPROCESSOR
PPTX
Instruction set and instruction execution cycle
PPTX
Assembly Language Programming
PPTX
Arithmetic instructions
PDF
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
PPTX
Instruction Set of 8086 Microprocessor
PPT
8255 presentaion.ppt
PDF
Assembly language 8086
PPTX
Interrupts of microprocessor 8085
PPTX
Dma and dma controller 8237
PPT
8086-instruction sets.ppt
DOCX
Block diagram of 80286
PPTX
8086 microprocessor
PDF
Soc architecture and design
PPT
8085 interrupts
PDF
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
PPT
Addressing mode of 8051
PPTX
File in C language
Assembly Language Lecture 4
Guia 3
INTEL 8086 MICROPROCESSOR
Instruction set and instruction execution cycle
Assembly Language Programming
Arithmetic instructions
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
Instruction Set of 8086 Microprocessor
8255 presentaion.ppt
Assembly language 8086
Interrupts of microprocessor 8085
Dma and dma controller 8237
8086-instruction sets.ppt
Block diagram of 80286
8086 microprocessor
Soc architecture and design
8085 interrupts
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
Addressing mode of 8051
File in C language
Ad

Similar to Lecture6 (20)

PDF
PDF
Lecture5(1)
PPT
1344 Alp Of 8086
PDF
Chapter 4 instruction set of 8086 microprocessor.pdf
PDF
Chapter 5 and 6 instructions and program control instructions.pdf
PPT
Instruction set of 8086
PDF
Alp 05
PDF
PPTX
Keyboard interrupt
PPT
EMBEDDED SYSTEMS 4&5
PPTX
instructionsetsofjdtufgmictfgfjh8086.pptx
PPT
Stack and subroutine
PDF
Instructionsetof8086 180224060745(3)
DOCX
Instruction set of 8086
PPTX
Part III: Assembly Language
DOCX
Assembly language
PPTX
PDF
8086 instructions
PDF
Chapter 6 Flow control Instructions
Lecture5(1)
1344 Alp Of 8086
Chapter 4 instruction set of 8086 microprocessor.pdf
Chapter 5 and 6 instructions and program control instructions.pdf
Instruction set of 8086
Alp 05
Keyboard interrupt
EMBEDDED SYSTEMS 4&5
instructionsetsofjdtufgmictfgfjh8086.pptx
Stack and subroutine
Instructionsetof8086 180224060745(3)
Instruction set of 8086
Part III: Assembly Language
Assembly language
8086 instructions
Chapter 6 Flow control Instructions
Ad

More from misgina Mengesha (15)

PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PDF
PPT
Sensors2006
PPT
Sensors31
PPT
Sensing for robotics and control s set13
PPT
Introduction to sensors
PPT
Cn3 sensors and transducers-12
PPT
Cn3 sensors and transducers-1
PPT
480 sensors
PPTX
Sensors2006
Sensors31
Sensing for robotics and control s set13
Introduction to sensors
Cn3 sensors and transducers-12
Cn3 sensors and transducers-1
480 sensors

Lecture6

  • 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