- •Course project handbook on “Programming” Donetsk, DonNtu, 2012
- •Contents
- •Introduction
- •1 Technical task
- •Technical task
- •2 Analyses of virtual computer
- •2.1 General architecture
- •2.2 Memory organizations. Data formats. Addressing modes
- •3 Programming in code of virtual computer
- •3.1 Programming in code of One-address Virtual Computer
- •3.2 Programming in code of Two-address Virtual Computer
- •3.3 Programming in code of Three-address Virtual Computer
- •4 Simulation program developing
- •4.3 Alu simulation and visualization
- •Void alu(int cop)
- •Appendix a general requests to the reports’ preparing
- •1. Program documentation
- •1.2. Programmer’s Manual
- •Formal report example
- •Title Page example
3 Programming in code of virtual computer
3.1 Programming in code of One-address Virtual Computer
y=a*b+d*c-f, where
a=5=5h=00000101
b=4=4h=00000100
c=20=14h=00010100
d=-5=-5h=11111011
f=-20=-14h=11101100
Example for VC: 13 bits memory word, 1-address computer, 256 words=>8 bits address. All operations are performed between accumulator (AC) and the 2d operand (Aex). Result is stored to AC.
Aex=A1, if MA=0 (direct addressing mode);
Aex=(A1[7…0]), if MA=1 (indirect addressing mode).
Load: (Aex)=>AC
Save: (AC)=>Aex
Bits’ numeration |
Data | |||
7…….0 |
13…9 |
8 |
7……….0 |
|
10 |
0000 |
0 |
0000 0101 |
a=5 |
11 |
0000 |
0 |
0000 0100 |
b=4 |
12 |
0000 |
0 |
0001 0100 |
c=20=14h |
13 |
1111 |
1 |
1111 1011 |
d=-5 |
14 |
1111 |
1 |
1110 1100 |
f=-20 |
15 |
0000 |
0 |
0000 0000 |
y=? |
16 |
0000 |
0 |
0000 0000 |
w=? |
Address (hexadecimal) |
Code of Operation |
MA |
A1 |
Comments |
20 |
0001 |
0 |
0001 0011 |
d=>AC |
21 |
1010 |
0 |
0001 0010 |
AC*c=>AC |
22 |
0010 |
0 |
0001 0110 |
AC=>w |
23 |
0001 |
0 |
0001 0001 |
b=>AC |
24 |
1010 |
0 |
0001 0000 |
AC*a=>AC |
25 |
1000 |
0 |
0001 0110 |
AC+w=>AC |
26 |
1001 |
0 |
0001 0100 |
AC-f=>AC |
27 |
0010 |
0 |
0001 0101 |
AC=>y |
28 |
0000 |
0 |
0000 0000 |
stop |
Characteristics:
Data volume Vd =7*13 bits = 91 bites = 12 bytes.
Program volume Vp =9*13 bits = 117 bits = 16 bytes.
Time of execution Tex =2(+/-)+2(*)+8 (access to memory).
3.2 Programming in code of Two-address Virtual Computer
y=a*b+d*c-f, where
a=5=5h=00000101
b=4=4h=00000100
c=20=14h=00010100
d=-5=-5h=11111011
f=-20=-14h=11101100
Example for VC: 24 bits memory word, 2-address computer, 256 words=>8 bits address
Operation: – is defined by the field MI
00 – (A1)op(A2)=>AC,A2
01 - (A1)op(AC)=>AC
10 - (A1)op(AC)=>A2
11 – (A1) op (A2) =>AC
Mov: (A1)=>A2
Bit’s numeration |
Data | |||||
7…….0 |
23…20 |
19…16 |
15………8 |
7……….0 | ||
10 |
0000 |
0000 |
0000 0000 |
0000 0101 |
a=5 | |
11 |
0000 |
0000 |
0000 0000 |
0000 0100 |
b=4 | |
12 |
0000 |
0000 |
0000 0000 |
0001 0100 |
c=20=14h | |
13 |
1111 |
1111 |
1111 1111 |
1111 1011 |
d=-5 | |
14 |
1111 |
1111 |
1111 1111 |
1110 1100 |
-f=-20 | |
15 |
0000 |
0000 |
0000 0000 |
0000 0000 |
y=? | |
16 |
0000 |
0000 |
0000 0000 |
0000 0000 |
w=? | |
Address (hexadecimal) |
Code of Operation |
MI |
MA |
A1 |
A2 |
Comments |
20 |
0010 |
00 |
00 |
0001 0110 |
0001 0011 |
d=>w |
21 |
1010 |
00 |
00 |
0001 0010 |
0001 0110 |
w*c=>w |
22 |
1010 |
11 |
00 |
0001 0000 |
0001 0001 |
b*a=>AC |
23 |
1000 |
01 |
00 |
0001 0110 |
0000 0000 |
AC+w=>AC |
24 |
1000 |
10 |
00 |
0001 0100 |
0001 0101 |
AC+(-f)=>y |
25 |
0000 |
00 |
00 |
0000 0000 |
0000 0000 |
stop |
Characteristics:
Data volume Vd =7*24 bits = 21 bytes.
Program volume Vp =6*24 bits = 18 bytes.
Time of execution Tex =2(+/-)+2(*)+10 (access to memory)