F28PL1 Programming Languages Lecture 5: Assembly Language 4.

Slides:



Advertisements
Similar presentations
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
Advertisements

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
The University of Adelaide, School of Computer Science
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Programming Languages and Paradigms
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Subroutines reasons for subroutines −repeat same code, or similar code with slightly different parameters −hide design decisions or design complexity −partition.
F28PL1 Programming Languages Lecture 20: Summary.
Typed Assembly Languages COS 441, Fall 2004 Frances Spalding Based on slides from Dave Walker and Greg Morrisett.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Run time vs. Compile time
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
Chapter 9: Subprogram Control
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Chapter 8 :: Subroutines and Control Abstraction
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Imperative Programming
F28PL1 Programming Languages Lecture 10: Programming in C 5.
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
C Programming language
Runtime Environments Compiler Construction Chapter 7.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Compiler Construction
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Programming Languages and Paradigms Imperative Programming.
COMP3190: Principle of Programming Languages
F28PL1 Programming Languages Lecture 4: Assembly Language 3.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
Intermediate Representation II Storage Allocation and Management EECS 483 – Lecture 18 University of Michigan Wednesday, November 8, 2006.
Arrays and Strings in Assembly
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
8086/8088 Instruction Set, Machine Codes and Addressing Modes.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
F28HS2 Hardware-Software Interface Lecture 12: Assembly Language 6 & Summary.
The Stack. ARMSim memory space: 0x Unused 0x x11400 Stack 0x x09400 Heap 0x?????-0x01400 Data 0x x????? Text 0x x01000.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Writing Functions in Assembly
Names and Attributes Names are a key programming language feature
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
The Stack.
Introduction to Compilers Tim Teitelbaum
Writing Functions in Assembly
BIC 10503: COMPUTER ARCHITECTURE
Chapter 9 :: Subroutines and Control Abstraction
Instructions - Type and Format
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
CSCE Fall 2013 Prof. Jennifer L. Welch.
The University of Adelaide, School of Computer Science
Binding Times Binding is an association between two things Examples:
CSCE Fall 2012 Prof. Jennifer L. Welch.
ECE 3430 – Intro to Microcomputer Systems
UNIT V Run Time Environments.
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Corresponds with Chapter 5
Presentation transcript:

F28PL1 Programming Languages Lecture 5: Assembly Language 4

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

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

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

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...

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 0x x B 0x F 0x MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 R4 LR 0x x x BX LR 0x B 0x F R5 SQ1

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 0x B MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x F MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x B MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x F MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x x10 R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x x10 R5 0x x B 0x F 0x x x x B 0x F SQ1

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 0x MUL R5,... MOV R3,#4 BL SQ1 MUL R4,... B ENDL ADD R4,R5 LR BX LR 0x x10 R5 0x x B 0x F 0x x x x B 0x F SQ1

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

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

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} 0x x x x POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR R4 LR 0x F 0x F 0x R5 0x x200001FC 0x200001F8 SP0x PUSH {R2} 0x x F PUSH {R3} PUSH {R5} POP {R4} 0x x F R6 SQ2

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} 0x POP {R5} BL SQ2 MUL R5,R5 B ENDL BX LR R4 LR R5 0x x200001FC 0x200001F8 SP0x PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} R6 0x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x F R4 LR R5 SP0x200001FC R6 0x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x R4 LR R5 SP0x200001F8 R6 0x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x R4 LR R5 SP0x200001F8 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x R4 LR R5 SP0x200001FC 0x04 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x F R4 LR 0x03 R5 SP0x x04 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x F R4 LR 0x19 R5 SP0x x10 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x R4 LR 0x19 R5 R130x200001FC 0x10 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x R4 LR 0x19 R5 SP0x200001FC 0x10 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

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 0x x04 0x200001FC 0x200001F8 PUSH {R2} PUSH {R3} PUSH {R5} POP {R4} 0x03 R2 0x04 R3 PC0x F 0x19 R4 LR 0x19 R5 SP0x x10 R6 0x x x x x F 0x F 0x x x F 0x x F SQ2

Nested subroutines push LR (& working registers) onto stack before nested call pop LR (& working registers) off stack after nested return

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} 0x x x POP {LR} BL SQ B ENDL BL SQ BX LR 0x F 0x F 0x x x200001FC 0x200001F8 MOV R4,#2 0x x F BL QUAD BX LR MUL R4,R4 0x x R4 PC0x LR SP0x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x F LR SP0x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x LR SP0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x LR SP0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x02 R4 PC0x LR SP0x200001FC 0x F 0x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x F LR SP0x200001FC 0x F 0x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x F LR SP0x200001FC 0x F 0x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x04 R4 PC0x LR SP0x200001FC 0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x F LR SP0x200001FC 0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x LR SP0x200001FC 0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x LR SP0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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 0x x200001FC 0x200001F8 MOV R4,#2 BL QUAD BX LR MUL R4,R4 0x10 R4 PC0x LR SP0x x x x x x F 0x F 0x x x F 0x x SQ QUAD

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

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?

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

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

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

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

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

Data abstraction how may variables be bound to values? e.g Java: – initialising declaration – assignment – parameter passing

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?

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

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

Control abstraction how are commands structured? e.g. Java: – sequence block, nested method calls – choice if, switch – repetition while, for, iterators, recursion

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

Program abstraction encapsulation – abstract over data & control e.g. Java – classes/objects

Pragmatics what is mapping to byte machine? how implemented? how easy to read/write/debug? performance? use? etc...

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

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

Assembler summary: data abstraction registers: – scope/extent - whole program labels: – scope whole file + where imported – extent – whole program

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

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

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