Académique Documents
Professionnel Documents
Culture Documents
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
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
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
.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
mov ah, 4ch int 21h main endp cseg ends end main
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.
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
0A 0D
10 13
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.
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.
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
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.
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