S2
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
CLA 7800 Clear AC
CLE 7400 Clear E
CMA 7200 Complement AC
CME 7100 Complement E
CIR 7080 Circulate right AC and E
CIL 7040 Circulate left AC and E
REGISTER INC 7020 Increment AC
SPA 7010 Skip next instr. if AC is positive
SNA 7008 Skip next instr. if AC is negative
SZA 7004 Skip next instr. if AC is zero
SZE 7002 Skip next instr. if E is zero
HLT 7001 Halt computer
INP F800 Input character to AC
OUT F400 Output character from AC
SKI F200 Skip on input flag
I/O SKO F100 Skip on output flag
ION F080 Interrupt on
IOF F040 Interrupt off
3
6.1 ASSEMBLY TRANSLATION
4
LDA X
INC X
PRINT X
Assembler
0001 0100 1010 0111
5
Processors only understands machine language
instructions (0s and 1s).
Machine language is too complex for using in
software development, hence higher languages are
used.
Each family of processors has its own set of
assembly instructions.
6
How does an convert an assembly program
to a hexa program (machine/object code)??
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
int A = 83, B= -23 ,C;
C = A + B;
A)Write an assembly program, to run on the basic
computer, assume the program should start at
address 100h.
B) Translate the code into symbolic program
C)Translate the symbolic program hexadecimal
machine language program which would be
executed on the Mano’s basic computer.
9
//C++ code
int A = 83, B= -23 ,C;
C = A + B;
/
/
/
/
/
10
//C++ code
int A = 83, B= -23 ,C;
C = A + B;
ORG 100
LDA A /LOAD A FROM MEMORY TO AC
ADD B / ADD A & B AND STORE TO AC
STA C / STORE THE RESULTS TO C
HLT
A, DEC 83 / HEXA= 0053
B, DEC -23 / HEXA= FFE9
C, DEC 0
END
11
A pseudo instruction gives information about some phase of
translation.
12
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100
100 LDA A 100
101 ADD B 101
102 STA C 102
103 HLT 103
104 A, DEC 83 / HEXA= 0053 104
105 B, DEC -23 / HEXA= FFE9 105
106 C, DEC 0 106
END
13
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100 /Starts at address 100
100 LDA A 100 LDA 104
101 ADD B 101 ADD 105
102 STA C 102 STA 106
103 HLT 103 HLT
104 A, DEC 83 / HEXA= 0053 104 0053
105 B, DEC -23 / HEXA= FFE9 105 FFE9
106 C, DEC 0 106 0000
END
14
Assemblers typically read the assembly language source
code twice before they outputs machine code.
1. First Pass: the assembler checks to see if the instructions
are legal in the current assembly mode.
2. Second Pass: the assembler examines the operands for
symbolic references to memory locations and resolves
these symbolic references.
15
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
100 LDA 104 100
101 ADD 105 101
102 STA 106 102
103 HLT 103
104 0053 104
105 FFE9 105
106 0000 106
16
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
100 LDA 104 100 2104
101 ADD 105 101 1105
102 STA 106 102 3106
103 HLT 103 7001
104 0053 104 0053
105 FFE9 105 FFE9
106 0000 106 0000
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
LDA A /LOAD A FROM MEMORY TO AC
AND B / A AND B
STA F / STORE THE RESULTS TO C
HLT
A, DEC 83 / HEXA= 0053
B, DEC 10 / HEXA= FFE9
F, DEC 0
END
22
ASSEMBLY PROGRAM SYMBOLIC PROGRAM
ORG 100
100 LDA A 100 LDA 104
101 AND B 101 AND 105
102 STA C 102 STA 106
103 HLT 103 HLT
104 A, DEC 83 / HEXA= 0053 104 0053
105 B, DEC 10 / HEXA= FFE9 105 000A
106 F, DEC 0 106 0000
END
23
B- SYMBOLIC PROGRAM C- HEXA PROGRAM
100 LDA 104 100 2104
101 AND 105 101 0105
102 STA 106 102 3106
103 HLT 103 7001
104 0053 104 0053
105 000A 105 000A
106 0000 106 0000
24
ASSEMBLY HIGH LEVEL
Complicated to code and debug Simple to code and debug
Requires deep understanding of Minimal hardware knowledge is
the hardware (machine dependent) required (machine independent)
Compact executable code
Large executable code
Faster Slower
- Requires an assembler - Requires a compiler
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
Example: Arithmetic right-shift operation CLE / Clear E to 0
SPA / Skip if AC is positive
SPA if AC is positive, skip next CME / AC is negative
instruction (CME) CIR / Circulate E and AC 27 of
24
Write the assembly program that uses loops performs a left
logical shift of the variable A four times, then stores the
result to B.
a) Without using loops
b) Using loops
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