Professional Documents
Culture Documents
18 Machine4
18 Machine4
Machine Language 1
Computer Systems
COMP1917: Computing 1
Recall: modern computer systems are layered.
18. Machine Language
Applications
Programming Language
Operating System
Assembly Language
Raw Machine
COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 2 COMP1917 15s2 18. Machine Language 3
1940’s
Some useful references for this material: First prototypes
Vacuum tubes
Machine language
J. Glenn Brookshear, “Computer Science: An Overview”, (4th ed), Ben- 1950’s
First commercial computers
Andrew S. Tanenbaum, “Structured Computer Organisation” (3rd ed), Prentice-Hall, Widespread use in business/defence
David Patterson and John Hennessy, “Computer Organization and Design: the 1970’s Minicomputers
Unix and C
Hardware/Software Interface”, Morgan-Kauffman, 1994. LSI/VLSI
1980’s Microprocessors
Windows, Mouse, Menus
Joseph Byrd and Robert Pettus, “Microprocessor Systems”, Prentice Hall, 1993. RISC
Output
display w/o medium CRT, LC, ...
keyboard r/o low
mouse r/o low 1,3-button
• Processor: control, calculation other computers r/w varying networks
• Memory: data & program storage VR-helmet r/w high games
mechanical r/w low embedded
• Input/output: interface to the world
equipment systems
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 6 COMP1917 15s2 18. Machine Language 7
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 8 COMP1917 15s2 18. Machine Language 9
CPUs typically provide operations for: Real machines can’t execute C directly.
• data movement (reg-to-reg, reg-to-mem) Real machines execute their own machine code.
C program source
• comparison (e.g. ==, >, <, >=, <=) hello.s Assembly code
Simple task
hello.o Machine code
• program control (goto/branch)
Libraries Link gcc −o ...
• input/output (read, write) −l ...
hello
Machine code
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 10 COMP1917 15s2 18. Machine Language 11
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 14 COMP1917 15s2 18. Machine Language 15
x y x & y x y x | y
0 0 0 0 0 0
0 1 0 0 1 1
1 0 0 1 0 1
1 1 1 1 1 1
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 18 COMP1917 15s2 18. Machine Language 19
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 20 COMP1917 15s2 18. Machine Language 21
COMP1917 15s2 18. Machine Language 22 COMP1917 15s2 18. Machine Language 23
Negation Subtraction
How do we compute the negative of a number? Using the instruction set for this simple machine, write a machine-
Step 1: XOR with FF (1’s complement) language routine equivalent to the C code:
Assume that m, n and k are stored in memory locations 10, 12 and 14,
respectively, and that program execution begins from location 20.
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
COMP1917 15s2 18. Machine Language 24 COMP1917 15s2 18. Machine Language 25
COMP1917 15s2 18. Machine Language 26 COMP1917 15s2 18. Machine Language 27
COMP1917 c
Alan Blair, UNSW, 2006-2015 COMP1917 c
Alan Blair, UNSW, 2006-2015
Exercise
int a, b, min;
min = b;
if( a < b ) {
min = a;
}
COMP1917 c
Alan Blair, UNSW, 2006-2015