Mips learn

aim:

记录mips学到的

—————————————————————————————————————————————————————————–

pc

program counter

lo hi

These are special registers used to store result of multiplication and division. They are not directly addressable. Their contents are accessed with special instruction mfhi and mflo

Assembly language

Assembly language programs are line-oriented. That is, the assembler translates an assembly language program one line at a time. The assembler recognizes four types of lines: empty lines, label definition lines, directive lines, and instruction lines.A line that only has spaces or tabs (i.e., white space) is an empty line. Empty lines are ignored by the assembler.

三种lines

label definition line
directive line
instruction line

三种lines的details

A label definition line consists of a label definition. A label definition consists of an identifier followed by a colon (“:”). As in most programming languages, an identifier must start with a letter (or an underscore) and may be followed by any number of letters, underscores, and digits.
A directive line consists of an optional label definition, followed by the name of an assembler directive, followed by the arguments for the directive. In this lab we will consider three assembler directives: .data, .word, and .text.
An instruction line consists of an optional label definition, followed by the name of an operation, followed by the operands. In this lab we will consider five operations: load, store, set, add, and sub.

labels

In an assembly language program, a label is simply a name for an address. For example, given the declarations shown in Example 2.1, “x” is a name for the address of a memory location that was initialized to 23.

Directives

three basic directives: .data, .text, and .word. The first two (.data and .text) are used to separate variable declarations and assembly language instructions. The .word directive is used to allocate and initialize space for a variable.

Each group of variable declarations should be preceded by a .data directive. Each group of assembly language instructions should be preceded by a .text directive. Using these directives, you could mix variable declarations and assembly language instructions; however, for the present, your assembly language programs should consist of a group of variable declarations followed by a group of assembly language instructions.

A variable declaration starts with a label definition (the name of the variable), followed by a .word directive, followed by the initial value for the variable. The assembler supports a fairly flexible syntax for specifying the initial value. For now, we will use simple integer values to initialize our variables. By default, the assembler assumes that numbers are expressed using decimal notation. You can use hexadecimal notation if you use the “0x” prefix. Example 2.1 illustrates a group of variable declarations.

Example: Give directives to allocate space for three variables, x, y, and z. You should initialize these variables to decimal 23, hexadecimal 3fce, and decimal 42, respectively.
.data ! start a group of variable declarations
x: .word 23 ! int x = 23;
y: .word 0x3fce ! int y = 0x3fce;
z: .word 42 ! int z = 42;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值