Download presentation
Presentation is loading. Please wait.
Published byCorey Phelps Modified over 9 years ago
1
F28PL1 Programming Languages Lecture 5: Assembly Language 4
2
Subroutines block of code with: – single entry point – ability to return to instruction after call basis of methods/procedures/functions subroutine call must: – remember address of instruction for return – transfer control to address of start of subroutine R14 == LR – link register – holds return address
3
Subroutine call BL label copy PC+4 to LR – i.e. set LR to address following BL instruction branch to label – i.e. set PC to address for label so: – label is name of subroutine – after call, LR holds return address
4
Subroutine return BX label – branch indirect on label – i.e. set PC to address from label so: – BX LR returns to instruction after last BL
5
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL... SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR...
6
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... R2 R3 PC MOV R2,#3 0x08000128 0x0800012B 0x0800012F 0x08000128 MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 R4 LR 0x08000134 0x08000138 0x08000144 BX LR 0x0800013B 0x0800013F R5 SQ1
7
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 R3 R4 PC MOV R2,#3 0x0800012B MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
8
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 R4 PC MOV R2,#3 0x0800012F MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
9
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 R4 PC MOV R2,#3 0x08000138 MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x08000134 R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
10
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 0x09 R4 PC MOV R2,#3 0x0800013B MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x08000134 R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
11
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 0x09 R4 PC MOV R2,#3 0x0800013F MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x08000134 0x10 R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
12
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 0x19 R4 PC MOV R2,#3 0x08000144 MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x08000134 0x10 R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
13
Example: R4 = R2*R2+R3*R3 MOV R2,#3 MOV R3,#4 BL SQ1 B ENDL SQ1MUL R4,R2,R2 MUL R5,R3,R3 ADD R4,R5 BX LR ENDL... 0x03 R2 0x04 R3 0x19 R4 PC MOV R2,#3 0x08000134 MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x08000134 0x10 R5 0x08000128 0x0800012B 0x0800012F 0x08000134 0x08000138 0x08000144 0x0800013B 0x0800013F SQ1
14
Parameter passing registers – fast – ties up specific registers – may not have enough spare registers on stack – push from registers before call – pop into registers in subroutine – not register specific – slower
15
Example: stack parameter passing PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL
16
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL 0x03 R2 0x04 R3 PC POP {R6} 0x08000154 0x08000158 0x08000144 0x08000138... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR R4 LR 0x0800014F 0x0800015F 0x08000174 R5 0x20000200 0x200001FC 0x200001F8 SP0x20000200 PUSH {R2} 0x08000138 0x0800013F PUSH {R3} PUSH {R5} POP {R4} 0x08000148 0x0800016F R6 SQ2
17
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL 0x03 R2 0x04 R3 PC POP {R6} 0x08000138... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR R4 LR R5 0x20000200 0x200001FC 0x200001F8 SP0x20000200 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} R6 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
18
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x0800013F R4 LR R5 SP0x200001FC R6 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
19
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x08000144 R4 LR R5 SP0x200001F8 R6 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
20
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x08000154 R4 LR R5 SP0x200001F8 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
21
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x08000158 R4 LR R5 SP0x200001FC 0x04 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
22
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x0800015F R4 LR 0x03 R5 SP0x20000200 0x04 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
23
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x03 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x0800016F R4 LR 0x19 R5 SP0x20000200 0x10 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
24
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x19 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x08000174 R4 LR 0x19 R5 R130x200001FC 0x10 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
25
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x19 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x08000148 R4 LR 0x19 R5 SP0x200001FC 0x10 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
26
Example: stack parameter passing... PUSH {R2} PUSH {R3} BL SQ2 POP {R4} B ENDL SQ2POP {R6} POP {R5} MUL R5,R5 MUL R6,R6 ADD R5,R6 PUSH {R5} BX LR ENDL POP {R6}... POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR 0x19 0x20000200 0x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x0800014F 0x19 R4 LR 0x19 R5 SP0x20000200 0x10 R6 0x08000148 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000174 0x08000138 0x0800013F 0x08000148 0x0800016F SQ2
27
Nested subroutines push LR (& working registers) onto stack before nested call pop LR (& working registers) off stack after nested return
28
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} 0x08000154 0x08000158 0x08000144 POP {LR} BL SQ B ENDL BL SQ BX LR 0x0800014F 0x0800015F 0x08000164 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 0x08000138 0x0800013F BL QUAD BX LR MUL R4,R4 0x08000148 0x08000168 R4 PC0x08000138 LR SP0x20000200 SQ QUAD
29
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x0800013F LR SP0x20000200 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
30
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x08000154 LR SP0x20000200 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
31
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x08000158 LR SP0x20000200 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
32
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x08000148 LR SP0x200001FC 0x0800015F 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
33
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x0800014F LR SP0x200001FC 0x0800015F 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
34
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x0800015F LR SP0x200001FC 0x0800015F 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
35
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x08000148 LR SP0x200001FC 0x08000164 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
36
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x0800014F LR SP0x200001FC 0x08000164 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
37
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x08000164 LR SP0x200001FC 0x08000164 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
38
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x08000168 LR SP0x20000200 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
39
Example: R4 = R4 4 MOV R4,#2 BL QUAD B ENDL SQMUL R4,R4 BX LR QUADPUSH {LR} BL SQ POP {LR} BX LR ENDL... PUSH {LR} POP {LR} BL SQ B ENDL BL SQ BX LR 0x20000200 0x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x08000144 LR SP0x20000200 0x08000144 0x08000154 0x08000158 0x08000144 0x0800014F 0x0800015F 0x08000164 0x08000138 0x0800013F 0x08000148 0x08000168 SQ QUAD
40
Recursion: R4 = R2 R3 pow(int R2, int R3, int R4) { if(R3==0) return R4; pow(R2,R3-1,R4*R2); } pow (2,3,1) pow (2,2,2) pow (2,1,4) pow (2,0,8) 8 MOV R2,#2 MOV R3,#3 MOV R4,#1 BL POW... POWCMP R3,#0 BEQ ENDPOW MUL R4,R2 SUB R3,#1 PUSH {LR} BL POW POP {LR} ENDPOWBX LR
41
Summarising language characteristics how does a language abstract away from underlying byte machines? – types – data abstraction – control abstraction what are pragmatic consequences of language characteristics? – i.e. how do characteristics affect use?
42
Types values & operations what are base types? – e.g. Java: int, float, char etc what are structured types? – e.g. Java: object, array, String etc
43
Types how do types constrain language? weak v strong typing – i.e. whether type associated with entity can (weak) or can’t (strong)change – e.g. Java: strong typing static v dynamic typing – i.e. whether types checked at compile time (static) or run time (dynamic) – e.g. Java: static typing
44
Polymorphism type abstraction – can types be generalised? – polymorphism == many shapes ad-hoc v parametric polymorphism – ad-hoc == “for this” i.e. language/context specific – parametric == controlled by parameters
45
Polymorphism e.g. Java – ad-hoc polymorphism operator overloading i.e. can use some operators with different types e.g. arithmetic – parametric polymorphism i.e. generic types with type variables
46
Data abstraction memory abstraction variable as name/value abstraction from address/contents – e.g. Java: variables where may variables be introduced? – e.g. Java: class fields, method formal parameters, block/method bodies, iteration control
47
Data abstraction how may variables be bound to values? e.g Java: – initialising declaration – assignment – parameter passing
48
Data abstraction scope – i.e. where is something visible? – lexical v dynamic scope – i.e. constrained or not by site of definition/declaration extent – i.e. how long does something exist?
49
Data abstraction e.g. Java: lexical scope – class field/method names visible via object – variables in block/ method body visible in block unless redefined – method formal parameter visible in method body only e.g. Java: block extent – variables only exist in defining block/method body
50
Control abstraction structured operations as commands how are calculations performed? – e.g. Java: expression how is memory accessed? – e.g. Java: use variable name in expression context how is memory changed? – e.g. Java: assignment to variable
51
Control abstraction how are commands structured? e.g. Java: – sequence block, nested method calls – choice if, switch – repetition while, for, iterators, recursion
52
Control abstraction e.g. Java – control flow method call, return & break – procedural void method i.e. from control sequences – functional method with return type i.e. from expressions – call by reference parameter passing
53
Program abstraction encapsulation – abstract over data & control e.g. Java – classes/objects
54
Pragmatics what is mapping to byte machine? how implemented? how easy to read/write/debug? performance? use? etc...
55
Assembler summary: types no types – everything is a byte representations for: – numbers, characters etc no type checking – representation are conventional – can apply any operation to any byte sequence regardless of representation – i.e. ad-hoc polymorphism
56
Assembler summary: data abstraction names R0-R15, PC, LR, SP etc abstract from CPU registers labels abstract from memory addresses names and labels used as variables i.e. use name as operand to access/change register/memory no data structures – must craft explicitly from byte sequences
57
Assembler summary: data abstraction registers: – scope/extent - whole program labels: – scope whole file + where imported – extent – whole program
58
Assembler summary: control abstraction operators abstract from machine code must craft structured constructs from operator sequences no universal standards or conventions – but compilers/operating will define standards – e.g. for parameter passing
59
Assembler summary: pragmatics direct machine code abstraction 1 to 1 mapping from assembly language to machine code easier to program than machine code must be assembled to machine code very fast – same as machine code
60
Assembler summary: pragmatics hard to read/write/debug CPU specific – not portable – 1950s attempts at universal machine code (UNCOL) failed used for mission/system critical software – e.g. device drivers, BIOS, small embedded systems
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.