Sei sulla pagina 1di 31

Prima Dewi Purnamasari

Microprocessor
Computer Engineering Study Program
Department of Electrical Engineering
Universitas Indonesia
Macro
Similar with Procedure.
But Procedure has to be called using CALL, and return to main
program using RET
Macro is called using its name
Making a macro is similar to making a new opcode
When a macro is called, assembler will copy the whole
program inside the macro into the main program it
can be seen on the listing file

2 Prima Dewi Purnamasari 2012


Example of Procedure
TAMBAH PROC FAR USES AX,BX
MOV AX,DATA1 ; AX = DATA1
ADD AX,DATA2 ; AX = DATA1 + DATA2
ADD AX,DATA3 ; AX = DATA1 + DATA2 + DATA3
MOV DATA1,AX ; DATA1 = DATA1 + DATA2 + DATA3
RET
TAMBAH ENDP

To use the Procedure:

CALL TAMBAH ; DATA1 = DATA1 + DATA2 + DATA3

3 Prima Dewi Purnamasari 2012


Example of Macro
TAMBAH MACRO A, B, C ; define the macro & its passing parameters
PUSH AX ; save AX in stack
PUSH BX ; save BX in stack
MOV AX,A ; AX = A
MOV BX,B ; BX = B
ADD AX,BX ; AX = AX + BX = A + B
MOV BX,C ; BX = C
ADD AX,BX ; AX = AX + BX = A + B + C
MOV A,AX ; simpan hasil di A
POP BX ; return AX from stack
POP AX ; return BX fromstack
ENDM
To use the Macro:
TAMBAH DATA1,DATA2,DATA3 ;DATA1=DATA1+DATA2+DATA3

4 Prima Dewi Purnamasari 2012


Local label in macro
In a macro, we can define a label (variable), ut we have to devine it as
local and write right after the macro name.
Maximum 35 local label in a macro.

FILL MACRO WHERE, HOW_MANY


LOCAL FILL1
PUSH SI
PUSH CX
MOV SI,OFFSET WHERE
MOV CX,HOW_MANY
MOV AL,0
FILL1: MOV [SI],AL
INC SI
LOOP FILL1
POP CX
POP SI
ENDM

5 Prima Dewi Purnamasari 2012


Example MACRO in main program:
FILL MES1,5
FILL MES2,10

6 Prima Dewi Purnamasari 2012


INCLUDE
Makro dapat dibuat dalam file terpisah yang isinya hanya
makro saja, biasanya berekstensi .INC atau .MAC
Dapat dipanggil oleh program lain dengan instruksi
INCLUDE

7 Prima Dewi Purnamasari 2012


Using The Keyboard and Video
Display
This material can be read in 5th edition book

8
Read input from Keyboard
Read 1 character from keyboard and display it to Computer
Display (DOS) we can see what is typed

9 Prima Dewi Purnamasari 2012


Example:

MOV AH,01H ;choose function call no 01H


INT 21 ;access DOS (wait until user type 1 char)
MOV SATU,AL ;save ASCII from typed char to memory loc. 1

10 Prima Dewi Purnamasari 2012


Read 1 character from keyboard without display it to
Computer Display (DOS) we can not see what is typed

11 Prima Dewi Purnamasari 2012


Example:
MOV AH,06H ; choose function call no 06H
MOV DL,FFH
INT 21 ; access DOS (wait until user type 1 char)
MOV DUA,AL ;save ASCII from typed char to memory loc. 1

12 Prima Dewi Purnamasari 2012


Read a line of input until user press ENTER (ASCII 0DH)

13 Prima Dewi Purnamasari 2012


Contoh program:

.DATA
TIGA DB 257 DUP (?)

.CODE
MOV TIGA,255 ;mengisi byte pertama dari lokasi memori TIGA dengan 255
;karena function 0AH hanya memperbolehkan maksimal 255
;karakter yg bisa dibaca sekaligus
MOV DX,OFFSET TIGA ;pilih lokasi memori TIGA untuk menyimpan hasil input
MOV AH,0AH ;memilih function call no 0AH untuk membaca karakter2
;sampai diketikkan enter dengan ditampilkan ke display
INT 21H ;eksekusi ke DOS (menunggu sampai user mengetik maks 255
; karakter atau sampai mengetik ENTER)

14 Prima Dewi Purnamasari 2012


Menampilkan output ke Display
Menampilkan 1 buah karakter ke Display (dari register tertentu)

Function nomer 06H bisa juga digunakan untuk menulis ke display.


Sama persis dengan contoh di atas, cukup mengisi AH dengan 06H
dan DL dengan kode ASCII karakter yang ingin ditampilkan.

15 Prima Dewi Purnamasari 2012


Contoh program:

MOV DL,A ;menyimpan kode ASCII A ke register DL


MOV AH,02H ;memilih function call no 02H untuk menampilkan 1 karakter ke
;display
INT 21 ;eksekusi ke DOS (menampilkan apa yang ada di DL)
MOV DL,42H ;menyimpan kode ASCII B ke register DL
INT 21 ;eksekusi ke DOS (menampilkan apa yang ada di DL)
MOV DL,EMPAT ;menyimpan kode ASCII yang tersimpan di lokasi memori EMPAT ;
;ke register DL
INT 21 ;eksekusi ke DOS (menampilkan karakter ASCII ada di DL)

16 Prima Dewi Purnamasari 2012


Menampilkan sebaris karakter sampai ditemui karakter $
(ASCII 24H) dari lokasi memori tertentu

17 Prima Dewi Purnamasari 2012


Contoh program:

.DATA

LIMA DB KULIAH MIKROPROSESOR$

.CODE

MOV DX,OFFSET LIMA ;pilih lokasi memori LIMA untuk ditampilkan isinyaa
MOV AH,09H ;memilih function call no 09H untuk menampilkan
;karakter2 sampai karakter $ ditemukan di memori
INT 21 ;eksekusi ke DOS (menampilkan KULIAH MIKROPROSESOR di display)

18 Prima Dewi Purnamasari 2012


DATA CONVERSIONS

19
Problem set: Membuat program

20 Prima Dewi Purnamasari 2012


Converting from Binary to ASCII
There are 2 ways of converting:
By the AAM instruction if number is less than 100
By Horners Algorithm
1. Divide by 10, then save the remainder on the stack as a
significant BCD digit
2. Repeat step 1 until the quotient is 0
3. Retrieve each remainder and add 30H to convert to ASCII
before displaying

21 Prima Dewi Purnamasari 2012


Converting from Binary to ASCII by AAM
. DATA
TESTDATA DB 34
TEMP DB 3 DUP (?)

.CODE
MOV AL, TESTDATA
MOV AH,0
AAM
ADD AH,20H
CMP AL,20H
JE SAVE
ADD AH,10H
SAVE: MOV TEMP[0],AH
ADD AL,30H
MOV TEMP[1],AL
MOV TEMP[2],0

22 Prima Dewi Purnamasari 2012


Converting from ASCII to Binary
The algorithm for converting from ASCII to binary is :
Begin with a binary result of 0
Subtract 30H from the character typed on the keyboard to
convert it to BCD
Multiply the result by 10 and add the new BCD digit
Repeat steps 2 and 3 until the character typed is not an ASCII-
coded number

Prima Dewi Purnamasari 2012


24 Prima Dewi Purnamasari 2012
Displaying and Reading Hexadecimal Data
Reading Hexadecimal Data
see Example 7-30
Displaying Hexadecimal Data
see Example 7-31

Prima Dewi Purnamasari 2012


26 Prima Dewi Purnamasari 2012
27 Prima Dewi Purnamasari 2012
Using Lookup Tables for Data Conversions
Using XLAT, a lookup table is formed in the memory as a
list of data that is referenced by a procedure to perform
conversions
Example 7-32 illustrates a lookup table that contains the 7-segment
codes for the numbers 0 to 9
Example 7-33 shows a table that references ASCII-coded character
strings located in the code segment

28 Prima Dewi Purnamasari 2012


Converting from BCD to 7-segment Code
Using a Lookup Table to Access ASCII Data
Data Conversions (contd)

Prima Dewi Purnamasari 2012

Potrebbero piacerti anche