Computer Architecture: Exploring MIPs, Assembly Code, and BIOS Functions

Week 5
Computers are like Old Testament gods; lots of rules and no
mercy.
Joseph Campbell
1
MIPs Assembler
Like most High Level Languages, assembly uses much of the same
practices.
Enter text as Assembly Code
Assemble the code producing machine code
Run the machine code.
2
Basic program format
data
Variables are declared here
text
Code goes here
3
Basic Program
#This is where variable definitions go
.data
theSolution:
 
.
word
 42
 
#in decimal
#This is where code goes
.text
Main:
 
 
lw
 $t0,theSolution  
 
#load value stored at address
 
addi
 $t0,$t0, 3     
 
#add 3 onto 42
 
move
 $a0, $t0
 
#output our value
 
li
 $v0, 1
 
syscall
  
 
li
 $v0, 10
  
# Systemcall code exit
 
syscall
4
Basic Program
All labels are denoted as:
someVariableName:
All of these can be viewed as memory addresses.
These are sometimes referred to as symbolic addresses
The Assembler will use these to:
Reference memory location
Control program flow
5
BIOS functions
B
asic 
I
nput 
O
utput 
S
ystem
All cpu architectures have one, just the name may be different.
X86 it is called the BIOS
Recall your PC has a BIOS
MIPs refers to it as the firmware routines
BIOS routines are drivers located in the firmware which interface the
OS to the hardware.
The OS has access to these, but are protected from user programs.
User software can access these OS routines which access the firmware by
making system calls to the OS.
To protect these subroutines, the OS switches to 
Kernel Mode
.
6
OS Kernel
Figure to the right
shows a typical
system.
The 
kernel
 is viewed
as the green and
purple sections.
To get to any
functionality you
must go through
protected system
calls
7
Typical BIOS routine example
User programs will load
specific registers with
output data, service #.
Issue a syscall.
OS determines what type
of syscall, and processes
the data accordingly.
When complete, control
returns to the user
program.
8
Sys Calls
MIPs has 17 standard
system calls.
MARS simulator has
extended system calls.
9
Load and Store Word
40% of all instructions will load and store data to/from the registers.
Lw $t0, some_label
Get the contents of memory address “some_label” and place it into register $t0.
At times it may be convenient to have the data address in the register
Lw $t0, ($t1)
($t1) indicates that the contents of $t1 is an address and should be treated as such.
This implies that addresses can be contained in registers and are thus susceptible to
arithmetic operations.
This allows for dynamic addressing control
.
La $t0, some_label
Loads the some_label address into a register.
Store instructions will work the same way
Sw $t0, some_label   -- in this case the contents of $t0 is placed into memory at
some_label
Sw $t0, ($t1)   - has a similar effect.
10
Hello World
Strings can be defined as
being null terminated or not.
.asciiz is null terminated.
La $a0, msg will load the base
address of msg into $a0 for
the syscall
Syscall will output the entire
message upto the null
character at the end of the
string.
11
Hello World!.
Stored in memory as a series of bytes.
Note the low byte of each word is on the right.
Null terminator is a 0.
12
Hello World!
Note what happens when
we remove the terminator
from the first string.
13
Byte Addressable Memory
MIPs uses byte addressable
memory.
Each address refers to a
unique byte in memory.
Words are collections of 4
bytes, and reside on
addresses exactly divisible
by 4.
First 3 lines can be reduced
to:  
lb $t1, msg + 4
14
Simple Arithmetic
Variables x and y are defined
and given 4 bytes of space in
memory.
Result is placed in x which
appears first in the 
.data
section, see below.
15
End
16
Slide Note
Embed
Share

Dive into the world of computer architecture with a focus on MIPs assembly language, basic program formats, BIOS functions, and system calls. Learn about the role of the OS kernel, memory addresses, and control flow in executing programs efficiently.

  • Computer architecture
  • MIPs assembly
  • BIOS functions
  • System calls
  • OS kernel

Uploaded on Oct 04, 2024 | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell 1

  2. MIPs Assembler Like most High Level Languages, assembly uses much of the same practices. Enter text as Assembly Code Assemble the code producing machine code Run the machine code. 2

  3. Basic program format data Variables are declared here text Code goes here 3

  4. Basic Program #This is where variable definitions go .data theSolution: .word 42 #in decimal #This is where code goes .text Main: lw $t0,theSolution #load value stored at address addi $t0,$t0, 3 #add 3 onto 42 move $a0, $t0 li $v0, 1 syscall li $v0, 10 syscall #output our value # Systemcall code exit 4

  5. Basic Program All labels are denoted as: someVariableName: All of these can be viewed as memory addresses. These are sometimes referred to as symbolic addresses The Assembler will use these to: Reference memory location Control program flow 5

  6. BIOS functions Basic Input Output System All cpu architectures have one, just the name may be different. X86 it is called the BIOS Recall your PC has a BIOS MIPs refers to it as the firmware routines BIOS routines are drivers located in the firmware which interface the OS to the hardware. The OS has access to these, but are protected from user programs. User software can access these OS routines which access the firmware by making system calls to the OS. To protect these subroutines, the OS switches to Kernel Mode. 6

  7. OS Kernel Figure to the right shows a typical system. The kernel is viewed as the green and purple sections. To get to any functionality you must go through protected system calls 7

  8. Typical BIOS routine example User programs will load specific registers with output data, service #. Issue a syscall. OS determines what type of syscall, and processes the data accordingly. When complete, control returns to the user program. 8

  9. Sys Calls MIPs has 17 standard system calls. MARS simulator has extended system calls. 9

  10. Load and Store Word 40% of all instructions will load and store data to/from the registers. Lw $t0, some_label Get the contents of memory address some_label and place it into register $t0. At times it may be convenient to have the data address in the register Lw $t0, ($t1) ($t1) indicates that the contents of $t1 is an address and should be treated as such. This implies that addresses can be contained in registers and are thus susceptible to arithmetic operations. This allows for dynamic addressing control. La $t0, some_label Loads the some_label address into a register. Store instructions will work the same way Sw $t0, some_label -- in this case the contents of $t0 is placed into memory at some_label Sw $t0, ($t1) - has a similar effect. 10

  11. Hello World Strings can be defined as being null terminated or not. .asciiz is null terminated. La $a0, msg will load the base address of msg into $a0 for the syscall Syscall will output the entire message upto the null character at the end of the string. 11

  12. Hello World!. Stored in memory as a series of bytes. Note the low byte of each word is on the right. Null terminator is a 0. String terminator. 12

  13. Hello World! Note what happens when we remove the terminator from the first string. 13

  14. Byte Addressable Memory MIPs uses byte addressable memory. Each address refers to a unique byte in memory. Words are collections of 4 bytes, and reside on addresses exactly divisible by 4. First 3 lines can be reduced to: lb $t1, msg + 4 14

  15. Simple Arithmetic Variables x and y are defined and given 4 bytes of space in memory. Result is placed in x which appears first in the .data section, see below. 15

  16. End 16

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#