You are on page 1of 23

Class Policies

• Course Number : EE 193


• Course Title : Assembly Language Program

• Unit Credits : 4 units (3 hrs lec/ 3 hrs lab)

• Class Schedule :
• Lecture : TF 4:00 – 5:30
• Course Prerequisite : Csc 101 and EE 177
Class Policies
• Course Description:
• Study of popular microprocessors and

microcomputer systems; assembly language


programming; assemblers and macro processors;
linkers and loaders.
• Course Coverage :
• Introduction to Assembly Language; the 80x86

architecture: organization of memory, addressing;


parts of an assembly language program; 80x86
instructions: general instructions, arithmetic,
decimal arithmetic, control; strings; interrupts
Class Policies
•Grading System :
Final Exam - 40%
MPs - 60%
References :
• ‘Assembler: Inside and Out’ by Harley Hahn
Introduction to Assembly Language
COMPUTER LANGUAGES

- The list of all the possible instructions that a


processor can perform is called its instruction
set
- The set of instructions that a processor can
execute directly, along with the rules for using
these instructions is called machine language
- Programmers use computer languages
instead of machine language to program
computers
COMPUTER LANGUAGES

• Computer languages
• High-level languages
• Closely resembles human language, easy to read
and write; far removed from machine language
• Includes C, C++, PASCAL, BASIC, FROTRAN, etc..

• Low-level languages
• Representation of machine language in a form that is
easy for us to work with
• Assembly language is a low-level language
COMPUTER LANGUAGES

•Computer languages must be translated into


machine language instructions, which is all
that the processor understands
• Compilers
• translate high-level language into machine language
• Assemblers
• translate assembly programs machine language
instructions
ASSEMBLY LANGUAGE
• Representation of machine language
Ex: Machine vs Assembly Language
Binary Hex Mnemonic Comment
11011011 DB IN ;input the 1st number
00000000 00 0 ;from port 0 and save in register A.
01000111 47 MOV B,A ;put a copy of register A in register B.
11011011
11011011 DB IN ;input the second number
00000000
00000000 00 0 ;from port 0 and save in register A.
10000000
10000000 80 ADD B ;add registers A and B, and leave the

11010011 ;sum in register A.


11010011
00000000 D3 OUT ;output registers A
00000000
01110110 00 0 ;to port
01110110 76 HLT ;halt

object code
Machine language Assembly language
ASSEMBLY LANGUAGE

• To program in assembly language, you must


understand (1) the instructions in the
instruction set and how to use them and (2)
the basic architecture of the machine
Operating System

• Operating system is the master control


program that runs the computer
• Assembly programmers will use OS in two
ways:
• we use OS to perform: commands to copy files,
start program, list a directory, etc..
• we call on OS from w/in our programs to perform
certain tasks; for example, input and output,
access clock, work with files and directories, etc..
Developing an Assembly Program

• We use ‘editors’ to enter our program


• We use assembler to translate our program
to machine language
• We use ‘linker’ to link our programs to other
programs/modules
Developing an Assembly Program
Source Code
Ex: TEST.ASM

Assembler

Object module
Ex: TEST.OBJ Other object modules

Linker

Load module
Ex: TEST.EXE
Why we need to know assembly programming?

• We may use assembly language to do


something that is impossible or awkward to do
with high-level languages
• To speed up programs and reduce size of
programs
• For us engineers, we need assembly
language:
• to understand how the machine operate
• for microprocessor-based designs

• for programming microcontrollers


Organization of Information within the
computer memory
• Bits and Bytes
• A bit is a digit that can only be zero or one
• Each group of 8 bits is called a byte

• Groups of Bits (for Intel 86 processors)


Number of Bits Name
8 Byte
16 Word (2 bytes)
32 Doubleword (2 bytes)
64 Quadword (8 bytes)
128 Paragraph (16 bytes)
Organization of Information within the
computer memory
• How characters are stored?
•ASCII code – American Standard Code for
Information Interchange, a standard code used to
store textual characters in memory, in which each
character is represented by a unique 8-bit pattern
Organization of Memory
• Memory Address
• Computer memory is organized by bytes
• All bytes are numbered starting from 0

• The number of a byte is called address

FFFFH
FFFEH
. .
Ex: 64kb memory . .
0005H
0004H
0003H
0002H
0001H
0000H
Organization of Memory
• How words are stored?
• Bytes are stored in a straightforward manner
• For words, least significant byte is stored first
followed by the most significant byte

0502H
Ex: Storing the data 1234H
0501H 12H
in
0500H 34H
memory location 500H

• Doublewords, quadwords and paragraph are


stored in the same manner as storing words
Organization of Memory
• Primary and Secondary memory
•Primary or main memory stores instructions and
data while a program is running
• The processor can work directly only with main
memory
• More commonly known as Read-Write Memory
(RWM) or Random-access memory (RAM)
• Secondary memory resides on the disks
•The processor cannot directly access the data in
secondary memory
•When we use memory, we mean the primary
memory
Organization of Memory
• Registers
• Registers refer to the read-write memory
locations built in to the processor
• Intel 86 processors contains 14 words of
registers, each with its own name and purpose
Organization of Memory
• Registers
Name Abbreviation Category
Accumulator AX (AH, AL) General register
Base register BX (BH, BL) General register
Count register CX (CH, CL) General register
Data register DX (DH, DL) General register
Base Pointer BP Offset register
Instruction pointer IP Offset register
Stack pointer SP Offset register
Destination index DI Offset register
Source index SI Offset register
Data segment register DS Segment register
Extra segment register ES Segment register
Stack segment register SS Segment register
Code segment register CS Segment register
Flag (none) (none)
Organization of Memory
• General Registers
• AX is the principal register used by arithmetic
instructions. Often used to accumulate results of
calculation
• BX can be used to hold a base address

• CX is used with certain instructions that perform


operations repeatedly. Used to keep track of the number
of repetitions of operations. Hence the name, count
register
• DX is called the data register because it is used to hold
data for general purposes
Organization of Memory
• The Stack
• A stack is a data structure that allows you to store and
recall data in last-in, first-out manner.
• When program starts, the stack has no data in it (empty).
When we use the stack to store data, it’s said that you
push it into the stack. When you recall data, you pop it off
the stack.
Organization of Memory
• The Stack
• Example of using the stack

PUSH 10 PUSH 87 POP PUSH 68 POP POP

10 87 10 68 10

10 10

You might also like