Assembly Language Programming Building Microcomputer
Assembly Language Programming Building Microcomputer
Reduced portability
programs run on only one type of CPU
The microprocessor can tell from the context whether an address refers to a byte or
a word
This figure shows the bit positions for a byte and a word
The positions are numbered from right to left, starting with 0
In a word, bits 0 to 7 form the low byte and bits 8 to 15 form the high byte
The low byte comes from the memory byte with the lower address
The processor can perform two operations on memory:
fetch -- read the contents of a location
store -- write data to a location
In a fetch, the processor only gets a copy of the data -- the original contents are
unchanged
In a store, the data written become the new contents of the location -- the original
contents are lost
A processor communicates with memory and I/O by using signals that travel along a
set of wires called a bus that connect the different components
There are three buses:
address bus
data bus
control bus
To fetch the contents of a memory location
The CPU places the address of the memory location on the address bus
The CPU sends a control signal to the memory circuits telling it to read from memory on
the control bus
It receives the data, sent by the memory circuits, on the data bus
The CPU
The CPU controls the computer by executing programs stored in memory
Each instruction is a bit string
For the 8086, instructions are from one to six bytes long
Execute
perform the operation on the data
store the result in memory if needed
The instruction that adds the contents of register AX to the contents of memory word 0 is
00000001 00000110 00000000 00000000
The first byte of the instruction is stored at the location indicated by the IP
1. Fetch the instruction
The BIU places a memory read request on the control bus and the address of the instruction on the
address bus
Memory responds by sending the contents of the location specified -- namely, the instruction just
given -- over the data bus
The CPU accepts the data and adds 4 to the IP so that the IP will contain the address of the next
instruction
2. Decode the instruction
On receiving the instruction, a decoder circuit in the EU decodes the instruction and determines
that it is an ADD operation involving the word at address 0
3. Fetch data from memory
The EU informs the BIU to get the contents of memory word 0
The BIU sends address 0 over the address bus and a memory read request is again sent over the control bus
The contents of memory word 0 are sent back over the data bus to the EU and placed in a holding register
To do so, the BIU sends out a memory write request over the control bus, the address 0 over the address bus, and the
sum to be stored over the data bus
The previous contents of memory word 0 are overwritten by the sum
The cycle is repeated for the instruction whose address is now contained in the IP
Even though machine instructions are very simple, their execution is actually quite
complex.
A clock circuit controls the processor by generating a train of clock pulses
The original IBM PC had a clock rate of 4.77MHz, but current Intel chips have clock
rates of over 1000MHz, or 1GHz
•Machine Language
•A CPU can only execute machine language instructions (which are bit strings)
Machine Instruction Operation
10100001 00000000 00000000 Fetch contents of memory word 0 and put it in register AX
•A program written in assembly language must be converted to machine language before the CPU can execute it
•A program called an assembler translates each assembly language statement into a single machine language instruction
Assembly language is easier than machine language, but it's still difficult because
the instruction set is so primitive
That is why high-level languages like C were developed
A program called a compiler is needed to translate a high-level language program
into machine code
A high-level language statement typically translates into many machine language
instructions
Sample Assembly Language Program
%TITLE "SAMPLE PROGRAM"
.MODEL SMALL
.STACK 100H
.DATA
A DW 2
B DW 5
SUM DW ?
.CODE
MAIN PROC
;initialize DS
MOV AX,@DATA
MOV DS,AX
;add the numbers
MOV AX,A ;AX has A
ADD AX,B ;AX has A+B
MOV SUM,AX ;SUM = A+B
;exit to DOS
MOV AX,4C00h
INT 21h
MAIN ENDP