assembly8086 tutorial
TRANSCRIPT
-
7/31/2019 Assembly8086 Tutorial
1/26
Tutorial
by: GLENN VON C. POSADAS
Presented by: Glenn Von C. Posadas
-
7/31/2019 Assembly8086 Tutorial
2/26
INTRODUCTION
Assembly Language is a low-levelprogramming language in which eachstatement corresponds directly to a single
machine instruction. It gives the computer-detailed command, thus it is specific to a givenprocessor.
Assembly Language might be used instead of ahigh-level language for any of the three majorreasons:
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
3/26
INTRODUCTION: 3 MAJOR REASONS
SPEED
CONTROL
PREFERENCES
It provides precise control of the computer. Theused of assembly language lets a programmerinteract directly with the hardware (processor,
memory, display and input / output ports), thus itexecutes faster than those generated by thecompilers.
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
4/26
HOW TO: assemble, compile and run
Run the DOSbox.
Mount the hard drive where your TASM folder islocated. By typing: Mount DriveLetter: Driveletter:\
Locate your TASM folder: type cd TASM To assemble your program with a file extension .asm,
type TASM
To link, type: tlink \t (this applies only to
.COM programs. tlink to link .EXE programs Type to run the program
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
5/26
2 STRUCTURES OF ASSEMBLY
LANGUAGE
The two kinds/structure of Assembly Program
are:
1. The .COM (Read as dot com or COM)
program
and the second one is the
2. The .EXE (Read as dot ekse or EXE) program.
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
6/26
First of all, the .COM is a program that requires anassembler to run. And compared to .EXE
programs, .COM is smaller in size and its structurecodes are easy to memorize. So basically, I preferto use this during exams in our theoretical as wellas in our laboratory exams. HAHA!
On the other hand, the .EXE program DOESN'TREQUIRE an assembler ANYMORE!And it is bigger in size since it is a stand-alone
program. You can run it anytime you wantwithout using other program(Assembler)
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
7/26
.COM PROGRAM
cseg segment para 'code'
assume cs:cseg, ds:cseg, ss:cseg, es:cseg
org 100h
start: jmp begin;VARIABLE DECLARATION
begin:
;Codes
int 20h
cseg ends
end start
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
8/26
.EXE PROGRAM
sseg segment para stack 'stack'
dw 200h
sseg ends
dseg segment para 'data'
dseg ends
cseg segment para 'code'
;...CONTINUATION1
by: GLENN VON C. POSADAS
;CONTINUATION HERE
main proc far
assume cs:cseg,ds:dseg,ss:sseg
mov ax, dseg
mov ds, ax
mov es, ax
mov ah, 4ch
int 21h
main endp
cseg ends
end main
-
7/31/2019 Assembly8086 Tutorial
9/26
Assembly Language 8086 Basic
Instructions
These are the most used instructions in 8086assembly language:
MOV instruction
Format: MOV {destination}, {source}This instruction can ONLY be used in the followingways:
REGISTER TO REGISTER
REGISTER TO MEMORY LOCATION IMMEDIATE TO REGISTER
IMMEDIATE TO MEMORY LOCATION
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
10/26
LEA (load effective address) instruction
Format: LEA {register}, {memory location}
This means that we can only use such
instruction in that way. This instruction is
usually used for printing a string.
CMP(compare) instruction
Compare Destination to Source.
We can use this to create and to use jumpinstructions.
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
11/26
Declaring Variables
For string:
VARIABLE_NAME db STRING HERE$
-note: put a $ in the end of the string toterminate. This serves as a null.
For Character:
VARIABLE_NAME db character
For a variable with null (or to initiate):
VARIABLE_NAME db ?
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
12/26
CONTROL CHARACTERS (from ASCII
TABLE)
HEX DECIMAL NAME FUNCTIO
07 7 BELL Emits a one-second
beep
08 8 BACKSPACE Moves the cursor
one column to the
left.
0A 10 Line Feed Moves the cursor
down one row
0D 13 Carriage Return Moves the cursor to
the beginning of
the line
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
13/26
Data Organization: DB, DW, and EQU
Bytes are allocated by define bytes DB.
Words are allocated by define words DW.
Both allow more than one byte or word to be allocated.
Question marks specify uninitialized data.
Strings allocate multiple bytes.
Labels in front of the directives remember offsets from thebeginning of the segment which accommodates the directive.
DUP allows to allocate multiple bytes. The following two linesproduce identical results:
DB ?, ?, ?, ?, ? DB 5 DUP(?)
Note that EQU directive does not allocate any memory: it creates aconstant value to be used by Assembler:
CR EQU 13 DB CR . mov al, CR
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
14/26
Complete Instruction Set
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
15/26
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
16/26
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
17/26
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
18/26
Some Important Interrupts for
8086/8088 microprocessors
INT 21h / AH=2 - write character to standard output.entry: DL = character to write, after execution AL = DL.
example: mov ah, 2 mov dl, 'a' int 21h
INT 21h / AH=1 - read character from standard input,with echo, result is stored in AL.if there is no character in the keyboard buffer, the
function waits until any key is pressed.
example: mov ah, 1 int 21h
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
19/26
INT 10h / AH = 2 - set cursor position.input:DH = row.DL = column.BH = page number (0..7).example: mov dh, 10 mov dl, 20 mov bh, 0 mov ah, 2 int 10h
INT 10h / AH = 09h - write character and attribute at cursor position.
input:AL = character to display.BH = page number.BL = attribute.CX = number of times to write character.INT 10h / AH = 0Ah - write character only at cursor position.
input:AL = character to display.BH = page number.CX = number of times to write character.
by: GLENN VON C. POSADAS
http://www.computing.dcu.ie/~ray/teaching/CA296/notes/8086_bios_and_dos_interrupts.htmlhttp://www.computing.dcu.ie/~ray/teaching/CA296/notes/8086_bios_and_dos_interrupts.htmlhttp://www.computing.dcu.ie/~ray/teaching/CA296/notes/8086_bios_and_dos_interrupts.htmlhttp://www.computing.dcu.ie/~ray/teaching/CA296/notes/8086_bios_and_dos_interrupts.htmlhttp://www.computing.dcu.ie/~ray/teaching/CA296/notes/8086_bios_and_dos_interrupts.html -
7/31/2019 Assembly8086 Tutorial
20/26
INT 10h / AH = 0Ch - change color for a single pixel.
input:
AL = pixel colorCX = column.DX = row.example: mov al, 13h mov ah, 0 int 10h ; set graphics video mode.mov al, 1100b mov cx, 10 mov dx, 20 mov ah, 0ch int 10h ; set pixel.
INT 10h / AH = 2 - set cursor position.input:DH = row.DL = column.BH = page number (0..7).example: mov dh, 10 mov dl, 20 mov bh, 0 mov ah, 2 int 10h
INT 20h - exit to operating system.
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
21/26
bit color table:
by: GLENN VON C. POSADAS
note: ; use this code for compatibility with dos/cmd
prompt full screen mode:
mov ax, 1003h
mov bx, 0 ; disable blinking.
int 10h
-
7/31/2019 Assembly8086 Tutorial
22/26
-
7/31/2019 Assembly8086 Tutorial
23/26
Attributes:
Blink --- Red --- Green --- Blue || Intens --- Red --- Green --- Blue
BACKGROUND TEXT
1 denotes on, 0 denotes off
Example:
Blinking character, Green Foreground, Violet
background (Blinking G/V)
1 1 0 1 || 0 0 1 0 ==> in hex ==> 0D2h
by: GLENN VON C. POSADAS
-
7/31/2019 Assembly8086 Tutorial
24/26
-
7/31/2019 Assembly8086 Tutorial
25/26
Answer:
cseg segment para 'code'
assume cs:cseg;ds:cseg;es:cseg;ss:cseg
org 100h
start: jmp begin
begin:
mov ax, 0003h
int 10h
mov ah,02hmov dh, 12
mov dl, 37
int 10h
by: GLENN VON C. POSADAS
mov ah,09h
mov al, 03h ;
mov bl, 84h
mov cx,1
int 10h
int 20h
cseg ends
end start
-
7/31/2019 Assembly8086 Tutorial
26/26
Dealing with STRINGS
by: GLENN VON C. POSADAS