03. Registers and memory

Supplemental: MIPS Assembly Language by Gary Shute

Convention
A set of terms on using architecture features in program. A convention can be broken by cost of (painful) incompatibility.

Registers

Alternate Name

Register Name

Use

$zero

$0

constant value 0

$s0 - $s8

$16 - $23, $30

saved values - preserved across calls

$sp

$29

stack pointer - preserved across calls

$ra

$31

return address - not preserved across calls

$a0 - $a3

$4 - $7

the first four parameters - not preserved across calls

$t0 - $t9

$8 - $15, $24 - $25

temporaries - not preserved across calls

$v0 - $v1

$2 - $3

expression evaluation and subprogram return value - not preserved across calls

$at

$1

reserved by the assembler - dangerous to use

$gp

$28

global pointer - dangerous to use

$k0 - $k1

$26 - $27

reserved by the operating system - dangerous to use

Flat memory model

memory.png

Data placement directives

Directive

Operand Syntax

Meaning

.globl

label { , label }*

Declare labels to be global

.data

none

Start a data declaration section

.text

none

Start an instruction section

.word

integer [ : non-negative integer ]

Declare a C int variable

.asciiz

string

Declare a string variable

.align

number

Align next address by 2**number bytes

Code addressing

E. g. (beware of meaningless code):

   1 .text
   2         li      $t0, 20
   3 start:  li      $t1, 5
   4         move    $t2, $t0
   5 loop:   beqz    $t2, fin
   6         subu    $t2, $t2, $t1
   7         b       loop
   8 fin:    sra     $t0, $t0, 1
   9         bnez    $t0, end
  10         j       start
  11 end:    nop

H/W

  1. EJudge: DoubleSum 'Double sum'

    Enter four integers, one in line, and add uniconditionally first one to third one, and second one to fourth one. Print results in two lines.

    Input:

    234
    -23
    23
    64
    Output:

    257
    41

HSE/ArchitectureASM/03_RegistersMemory (последним исправлял пользователь FrBrGeorge 2019-11-22 13:59:35)