Sie sind auf Seite 1von 42

Fundamental of Assembly Language

Programming (for Microprocessor)


Prima Dewi Purnamasari
Microprocessor
Electrical Engineering Department
Universitas Indonesia

Computer Language

High Level language

Low Level Language

Pascal, C, C++, Java, etc


Assembly

Machine Codes

010010001010100101010 in binary
1234 FFAB 1234 H in hexadecimal

Microprocessor (c) Prima Dewi Purnamasari 2011

Why Assembly?
Assembly has several features that make it a good choice many
some situations.
1. It's fast Assembly programs are generally faster than
programs created in higher level languages. Often,
programmers write speed-essential functions in assembly.
2. It's powerful You are given unlimited power over your
assembly programs. Sometimes, higher level languages have
restrictions that make implementing certain things difficult.
3. It's small Assembly programs are often much smaller
than programs written in other languages. This can be very
useful if space is an issue.

Microprocessor (c) Prima Dewi Purnamasari 2011

Preparation for Assembly Programming

Basically you will need:

Program editor as simple as Notepad


Assembler
1.
2.
3.

MASM http://www.masm32.com/.
TASM Made by Borland, a commercial product
NASM http://sourceforge.net/projects/nasm/

Be careful in writing your programs, because it runs directly


on your microprocessor!

Microprocessor (c) Prima Dewi Purnamasari 2011

Steps to Create a
Program

Microprocessor (c) Prima Dewi Purnamasari 2011

Creating an Assembly Language Program

An assembly language program should be written with any


text editor and have the extension filename.asm.
The assembler and Linker

The assembler program converts a symbolic source module


(file) into a hexadecimal object file
The linker program executes as the second part of ML, reads the
object files, created by the assembler program, and links them into
a single execution file (.EXE)

Microprocessor (c) Prima Dewi Purnamasari 2011

Microprocessor (c) Prima Dewi Purnamasari 2011

MASM32

Microprocessor (c) Prima Dewi Purnamasari 2011

TASM

Microprocessor (c) Prima Dewi Purnamasari 2011

Emulator

an emulator is hardware and/or software that duplicates (or


emulates) the functions of a first computer system in a different
second computer system, so that the behavior of the second
system closely resembles the behavior of the first system.

10

Microprocessor (c) Prima Dewi Purnamasari 2011

Emu8086

11

Microprocessor (c) Prima Dewi Purnamasari 2011

Individual Assignment

Download and install

emu8086 (trial)

http://www.emu8086.com/

Find corresponding tutorial on how to use it (available on the


Internet!), self study!

12

Microprocessor (c) Prima Dewi Purnamasari 2011

Group assignment

Each group is responsible to bring at minimum 1 laptop


(with emu8086 installed) to class every session

13

Microprocessor (c) Prima Dewi Purnamasari 2011

Assembly Program Structure

14

Microprocessor (c) Prima Dewi Purnamasari 2011

15

Microprocessor (c) Prima Dewi Purnamasari 2011

LIST File, generated


automatically after
program successfully
assembled

Memory
Address

16

Machine
codes

Microprocessor (c) Prima Dewi Purnamasari 2011

Writing Structure
NEXT:

MOV AX, [BX]


2

; comment

1=

label, followed by :
2= opcode
3= operand
4= comment, preceded with;
17

Microprocessor (c) Prima Dewi Purnamasari 2011

Writing Structure

Each statement in an assembly language program consists


of four parts or fields.
The leftmost field is called the label.

All labels must begin with a letter or one of the following


special characters: @, $, -, or ?.

used to store a symbolic name for the memory location it


represents

a label may have any length from 1 to 35 characters

The label appears in a program to identify the name of a


memory location for storing data and for other
purposes.
18

Microprocessor (c) Prima Dewi Purnamasari 2011

The next field to the right is the opcode field.


designed to hold the instruction, or opcode
the MOV part of the move data instruction is an example
of an opcode
Right of the opcode field is the operand field.
contains information used by the opcode
the MOV AL,BL instruction has the opcode MOV and
operands AL and BL
The comment field, the final field, contains a comment about
the instruction(s).
comments always begin with a semicolon (;)
19

Microprocessor (c) Prima Dewi Purnamasari 2011

Try it in emulator!
Click View and look the changes in every menu list:

20

registers
Data
Screen
Flags
etc

Microprocessor (c) Prima Dewi Purnamasari 2011

Computer Data Formats

21

Microprocessor (c) Prima Dewi Purnamasari 2011

Computer Data Formats

ASCII and Unicode Data


Binary Coded Decimal (BCD)
Byte-Sized Data
Word-Sized Data
Doubleword-Sized Data
Real Numbers

22

Microprocessor (c) Prima Dewi Purnamasari 2011

ASCII Data

23

American Standard Code for Information Interchange


(ASCII) data represent alphanumeric characters in the
memory of a computer system (Table 1.7)
The standard ASCII code is a 7-bit code with the eighth and
MSB used to hold parity in some systems
ASCII are most often stored in memory using a special
directive to the assembler program called define byte(s) or
DB

Microprocessor (c) Prima Dewi Purnamasari 2011

24

Microprocessor (c) Prima Dewi Purnamasari 2011

BCD Data

25

Binary-Coded Decimal (BCD) information is stored in


either packed or unpacked forms
Packed BCD data are stored as two digits per byte
Unpacked BCD data are stored as one digit per byte
The range of a BCD digit extends from 00002 to 10012 or
0-9 decimal
Table 1.9 shows some decimal numbers converted to both
packed ad unpacked BCD

Microprocessor (c) Prima Dewi Purnamasari 2011

26

Microprocessor (c) Prima Dewi Purnamasari 2011

Byte-Sized Data

Byte-size data are stored as unsigned and signed integers


Negative signed numbers are stored in the 2s complement
form

27

Whenever a number is 2s complement, its sign changes from


negative to positive or positive to negative
See example 1-22, 1-23

Microprocessor (c) Prima Dewi Purnamasari 2011

28

Microprocessor (c) Prima Dewi Purnamasari 2011

Define byte (DB) directive is used to store 8-bit data


in memory

Microprocessor (c) Prima Dewi Purnamasari 2011

29

Word-sized Data

A word (16-bits) is formed with two bytes of data


The LSB is always stored in the lowest-numbered memory
location, the MSB in the highest (i.e., little endian format)
used with Intel family of microprocessor
An alternate method (i.e., big endian format) is used with the
Motorola family of micro-processors

30

Microprocessor (c) Prima Dewi Purnamasari 2011

Word-sized Data

Fig 1.11(a) & (b) shows the weight of each bit position in a
word of data

31

Microprocessor (c) Prima Dewi Purnamasari 2011

32

Microprocessor (c) Prima Dewi Purnamasari 2011

Example 1.25 shows several signed and unsigned word-sized


data stored in memory using the assembler program
Note that define word(s) directive or DW causes the
assembler to store words in the memory

33

Microprocessor (c) Prima Dewi Purnamasari 2011

34

Microprocessor (c) Prima Dewi Purnamasari 2011

Doubleword-sized Data

35

Doubleword-sized data requires four bytes of memory


(32-bit number)
Doubleword-sized data appear as a product after a
multiplication and also as a dividend before a division
Fig. 1-12 shows the form used to store doublewords in the
memory and the binary weights of each bit position

Microprocessor (c) Prima Dewi Purnamasari 2011

36

Microprocessor (c) Prima Dewi Purnamasari 2011

To define doubleword-sized data, use assembler


directive define doubleword or DD

Microprocessor (c) Prima Dewi Purnamasari 2011

37

Real Numbers

38

A real number (floating-point number) contains two parts:


a mantissa, significant, or fraction and an exponent
Fig. 1-13 and example 1-27 depicts both the 4-byte (single
precision) and 8-byte (double precision) forms of real
numbers

Microprocessor (c) Prima Dewi Purnamasari 2011

39

Microprocessor (c) Prima Dewi Purnamasari 2011

The exponent is stored as a biased exponent

40

an exponent of 23 is represented as a biased exponent of 127+3


or 130 (82H) in the single- precision form or as 1026 (402H) in the
double-precision form

Microprocessor (c) Prima Dewi Purnamasari 2011

41

Microprocessor (c) Prima Dewi Purnamasari 2011

Reference/Text Book

The Intel Microprocessors, 8th Edition, Brey, Barry, B.,


Prentice Hall, USA, 2009

42

Das könnte Ihnen auch gefallen