Chapter 4
Chapter 4
S1 Bus
S0
Memory unit 7
4096 x 16
Address
Write Read
AR 1
LD INR CLR
PC 2
LD INR CLR
DR 3
LD INR CLR
E
ALU AC 4
LD INR CLR
INPR
IR 5
LD
TR 6
LD INR CLR
OUTR
Clock
LD
16-bit common bus
2
BASIC COMPUTER INSTRUCTIONS
Hex Code
Symbol I = 0 I=1 Description
AND 0xxx 8xxx AND memory word to AC
ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load AC from memory
MEMORY STA 3xxx Bxxx Store content of AC into memory
BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and save return address
ISZ 6xxx Exxx Increment and skip if zero
3
6.1 ASSEMBLY TRANSLATION
4
LDA X
INC X
PRINT X
Assembler
5
Processors only understands machine language
instructions (0s and 1s).
7
How does an convert an assembly program
to a hexa program (machine/object code)??
A- ASSEMBLY PROGRAM
B- SYMOLIC PROGRAM
(two passes)
C- HEXA PROGRAM
8
Example 1
Consider the following C-Language piece of code
//C++ code
/
/
/
/
/
10
//C++ code
int A = 83, B= -23 ,C;
C = A + B;
ORG 100
END
11
A pseudo instruction gives information about some phase of
translation.
12
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100
END
13
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100 /Starts at address 100
END
14
Assemblers typically read the assembly language source
code twice before they outputs machine code.
15
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
16
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
17
6.2 SIMPLE PROGRAMS
18
19
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100 ORG 100
100 LDA A 100 LDA 109
101 ADD B 101 ADD 10A
102 STA D 102 STA 10C
103 LDA C 103 LDA 10B
104 CMA 104 CMA
105 INC 105 INC
106 ADD D 106 ADD 10C
107 STA D 107 STA 10C
108 HLT 108 HLT
109 A, DEC 80 109 0050
10A B, DEC 10 10A 000A
10B C, DEC 30 10B 001E
10C D, DEC 0 10C 0000
END 20
Write an assembly program that computes the logical
operation F = A AND B.
//C++ code
int A = 83, B= 10 ,F;
F = A AND B;
21
//C++ code
int A = 83, B= 10 ,C;
F = A AND B;
ORG 100
END
22
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100
END
23
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
24
ASSEMBLY HIGH LEVEL
Faster Slower
25
6.3 LOOPS
26
• Basic Computer instructions have: CLE, CIR, CIL only
• Other shift operations can be implemented as follows.
CLE
Example: Logical shift-right operation CIR
CLE
Example: Logical shift-left operation
CIL
28
29
30
ISZ CTR Increment CTR and skip next instruction (BUN) if CTR is zero
31
Write the assembly program that uses loops
performs a right logical shift of the variable A 10
times, then stores the result to B.
32
33
34
Write the assembly program that multiplies two positive
numbers by repeated addition method. Initialize A and B to
250 and 350 respectively.
35
We make A negative and use it as the counter, increment it
and skip when it reaches zero. 36
6.4 ARRAYS
37
Write the assembly program that adds the elements of an
array of 100 words starting from memory location [150 h].
Store the result to the variable SUM.
38
Write the assembly program that adds the elements of an
array of 100 words starting from memory location [150 h].
Store the result to the variable SUM.
39
Write the assembly program that increments by 2 all
elements of an array of 300 words starting from memory
location [500h].
40
Program to Output a Character
41
Subroutine to Input 2 Characters and pack into a word
42