Vous êtes sur la page 1sur 26

Assembly Language

Tutorial
Presented by: Glenn Von C. Posadas
by: GLENN VON C. POSADAS

INTRODUCTION
Assembly Language is a low-level programming language in which each statement corresponds directly to a single machine instruction. It gives the computerdetailed command, thus it is specific to a given processor. Assembly Language might be used instead of a high-level language for any of the three major reasons:
by: GLENN VON C. POSADAS

INTRODUCTION: 3 MAJOR REASONS


SPEED CONTROL PREFERENCES

It provides precise control of the computer. The used of assembly language lets a programmer interact directly with the hardware (processor, memory, display and input / output ports), thus it executes faster than those generated by the compilers.
by: GLENN VON C. POSADAS

HOW TO: assemble, compile and run


Run the DOSbox. Mount the hard drive where your TASM folder is located. By typing: Mount DriveLetter: Driveletter:\ Locate your TASM folder: type cd TASM To assemble your program with a file extension .asm, type TASM <filename.asm> To link, type: tlink \t <filename> (this applies only to .COM programs. tlink <filename> to link .EXE programs Type <filename> to run the program

by: GLENN VON C. POSADAS

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

First of all, the .COM is a program that requires an assembler to run. And compared to .EXE programs, .COM is smaller in size and its structure codes are easy to memorize. So basically, I prefer to use this during exams in our theoretical as well as in our laboratory exams. HAHA! On the other hand, the .EXE program DOESN'T REQUIRE an assembler ANYMORE! And it is bigger in size since it is a stand-alone program. You can run it anytime you want without using other program(Assembler)
by: GLENN VON C. POSADAS

.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

.EXE PROGRAM
sseg segment para stack 'stack' dw 200h sseg ends dseg segment para 'data' dseg ends
;CONTINUATION HERE main proc far assume cs:cseg,ds:dseg,ss:sseg mov ax, dseg mov ds, ax mov es, ax

cseg segment para 'code' ;...CONTINUATION1

mov ah, 4ch int 21h main endp cseg ends end main

by: GLENN VON C. POSADAS

Assembly Language 8086 Basic Instructions


These are the most used instructions in 8086 assembly language: MOV instruction Format: MOV {destination}, {source} This instruction can ONLY be used in the following ways: REGISTER TO REGISTER REGISTER TO MEMORY LOCATION IMMEDIATE TO REGISTER IMMEDIATE TO MEMORY LOCATION
by: GLENN VON C. POSADAS

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 jump instructions.

by: GLENN VON C. POSADAS

Declaring Variables
For string: VARIABLE_NAME db STRING HERE$ -note: put a $ in the end of the string to terminate. 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

CONTROL CHARACTERS (from ASCII TABLE)


HEX 07 08 DECIMAL 7 8 BELL BACKSPACE NAME FUNCTIO Emits a one-second beep Moves the cursor one column to the left. Moves the cursor down one row Moves the cursor to the beginning of the line

0A 0D

10 13

Line Feed Carriage Return

by: GLENN VON C. POSADAS

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 the beginning of the segment which accommodates the directive. DUP allows to allocate multiple bytes. The following two lines produce identical results: DB ?, ?, ?, ?, ? DB 5 DUP(?) Note that EQU directive does not allocate any memory: it creates a constant value to be used by Assembler: CR EQU 13 DB CR . mov al, CR

by: GLENN VON C. POSADAS

Complete Instruction Set

by: GLENN VON C. POSADAS

by: GLENN VON C. POSADAS

by: GLENN VON C. POSADAS

by: GLENN VON C. POSADAS

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

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

INT 10h / AH = 0Ch - change color for a single pixel. input: AL = pixel color CX = 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

bit color table:


note: ; use this code for compatibility with dos/cmd prompt full screen mode: mov ax, 1003h mov bx, 0 ; disable blinking. int 10h

by: GLENN VON C. POSADAS

Printing a Character with ATTRIBUTES


Printing a character with attribute (cursor does not advance) mov ah, 09 --> service # mov al, [char] --> character to display (Enclosed in single quotes or an ASCII code) mov bh, [page] --> (page #, may be omitted) mov bl, [attribute in hex] --> attributes. refer below mov cx, [n] --> number of repetition int 10h --> Interrupt number
by: GLENN VON C. POSADAS

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

SEATWORK 1:
Make a program in assembly language that will display a red heart icon located at the center of the screen with blinking attribute.

by: GLENN VON C. POSADAS

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,02h mov 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

Dealing with STRINGS

by: GLENN VON C. POSADAS

Vous aimerez peut-être aussi