Download Using IAS instructions and more Slides Assembly Language Programming in PDF only on Docsity!
Cosc 2150:
Computer Organization
Simplified IAS language
The Computer Level Hierarchy
- (^) Each virtual machine layer is an abstraction of the level below it.
- (^) The machines at each level execute their own particular instructions, calling upon machines at lower levels to perform tasks as required.
- (^) Computer circuits ultimately carry out the work.
The Computer Level Hierarchy
• Level 4: Assembly Language Level
—Acts upon assembly language produced from Level 5,
as well as instructions programmed directly at this
level.
• Level 3: System Software Level
—Controls executing processes on the system.
—Protects system resources.
—Assembly language instructions often pass through
Level 3 without modification.
The Computer Level Hierarchy
• Level 2: Machine Level
—Also known as the Instruction Set Architecture (ISA)
Level.
—Consists of instructions that are particular to the
architecture of the machine.
—Programs written in machine language need no
compilers, interpreters, or assemblers.
The Computer Level Hierarchy
• Level 0: Digital Logic Level
—This level is where we find digital circuits (the chips).
—Digital circuits consist of gates and wires.
—These components implement the mathematical logic
of all other levels.
IAS Hardware
• There are 4 registers
- (^) PC = Program Counter
- (^) IR = Instruction Register
- (^) AC = Accumulator Register
- (^) MQ = Multiplier Quotient Register
- (^) Used in Multiplication and division.
Language
• See Handout
Example 1
main () { int a=15; int b=5; int c; c = a + b; } 0 15 a 1 5 b 2 0 c 3 begin 4 .c = a +b 5 load M(0) 6 add M(1) 7 stor M(2) 8 halt
Example 2 (continued)
0 15 1 5 2 a 3 b 4 c 5 begin
- a = 15 7 load M(0) 8 stor M(2)
- b = 5 10 load M(1) 11 stor M(3)
- c = a + b 13 add M(2) 14 stor M(4) 15 halt
Or you could
optimize the code a
little.
NOTE FOR
HOMEWORK.
You do not need to
optimize, but it
must be at least as
efficient as the
“original” code.
Example 3
main () { int a=15, b=5, c; if (a >= b) c = a – b; else c = a + b; } 0 15 a 1 5 b 2 c 3 begin
- If (a >=b) 4 load M(0) 5 sub M(1) 6 jump+ M(8) 7 jump M(12) 8 .true, c=a-b 8 load M(0) 9 sub M(1) 10 stor M(2) 11 jump M(15) 12 .false c = a+b 12 load M(0) 13 add M(1) 14 stor M(2) 15 halt
Example3 ( with a > b)
main () { int a=15, b=5, c; if (a > b) c = a – b; else c = a + b; } 0 15 a 1 5 b 2 c 3 1 4 begin
- a > b 5 load M(0) 6 sub M(1) 7 sub M(3) 8 jump+ M(10) 9 jump M(14)
- True, c = a- b 10 load M(0) 11 sub M(1) 12 stor M(2) 13 jump M(17)
- False, c = a + b 14 load M(0) 15 add M(1) 16 stor M(2) 17 halt
Example 4
main () { int x=0; while (x < 5) { x=x+1;//or ++x; } } A NOTE FOR HOMEWORK You CAN NOT change a top testing loop to a bottom testing loop! 0 5 1 1 2 0 x 3 begin
- While (x<5) 4 load M(2) 5 sub M(0) 6 jump+ M(11)
- X=x+ 7 load M(2) 8 add M(1) 9 stor M(2) 10 jump M(4) 11 halt
Example 5
main () { int I , x = 0; for (I =1;I<=6; ++I) { if (I % 2==0) { // % is mod, so I mod 2 x = x +I; } } x = x * 2; }
Code on next side.
Example 5 (continued)
0 7 1 1 2 2 3 i 4 0 x 5 begin
- i = 7 load M(1) 8 stor M(3)
- I<= 10 load M(3) 11 sub M(0) 12 jump+ M(27)
- If (I%2) 14 load M(3) 15 div M(2) 16 sub M(1) 17 jump+ M(23)
- x +=I; 19 load M(4) 20 add M(3) 21 stor M(4)
- ++I 23 load M(3) 24 add M(1) 25 stor M(3) 26 jump M(10)
- x = x * 27 load MQ,M(4) 28 mul M(2) 29 stor M(4) 30 halt