Transcript Document

ACOE301: Computer
Architecture II Labs
Lab conduct
•
•
•
•
•
Time: 1 period/week
Location: Room 12
Material: MIPS Assembly
Equipment: SPIM MIPS emulator, PC
Deliverables: Lab papers with source code
and answers to questions
• Deliverable submission mode: e-learning
page
SPIM
• a self-contained simulator that runs MIPS32
programs
• reads and executes assembly language
programs
• provides a simple debugger and minimal set of
operating system services
• does not execute binary (compiled) programs.
• Latest version is QTSPIM
http://spimsimulator.sourceforge.net/
Advantages of using a Simulator
• You can learn the language without having to buy a
MIPS-based computer
• The simulator provides debugging features
– single stepping through a Program
– watch the contents of the registers change as each instruction
executes
– look at the contents of memory as the instructions execute
– set breakpoints
• programming mistakes do not cause the machine
running the simulation to crash
• Disadvantage: Slow
Assembly language
• One-to-one relationship with machine
language unlike high-level languages
– Many lines of code even for simple
programmes
• Requires at least some knowledge of the
microprocessor architecture, memory
structure and operating system
• Not portable (source files will not run on a
different architecture microprocessor)
Why use Assembly Language
• Traditionally, more efficient use of the main memory
– Less memory required
– Programs execute faster
• Traditionally, avoid redundant instructions inserted by
compilers.
• Direct access to the hardware of the computer,
– Usually not supported or even prevented by compilers.
• Access to the microprocessor’s internal control registers.
• Embedded systems have tight constraints on
performance, memory size and power consumption
Additional Reasons for Learning Assembly
Language
• Understand the microprocessor
architecture
• Understand the hardware/software
interface
Typical Assembly Language
Instruction
LOOP: add $3, $3, $2 ;$3<-$3+$2
Label (optional)
Opcode
Destination operand
Source operand(s)
Comment (optional)
Assembler Directives
 Directives are instructions given by the programmer to the
assembler on how to assemble the program.
 Directives are not part of the instruction set of the microprocessor.
 The use of directives might vary from assembler to assembler.
 Some MIPS assembler directives:
 .data declares a data memory segment where you can declare
‘variables’
 .text declares a code memory segment where a program is stored
 .word declares word size (32-bit) variables or constants
 .byte declares byte size (8-bit) variables or constants
 .ascii declares a non null-terminated ascii string
 .asciiz declares a null-terminated ascii string