Skip to content

Review Chap 6&7

Away from machine codes, we are going to talk about programming languages. There are high-level and low-level languages. High-level languages tend to be ISA independent.

Assembly language is a low-level language. Low-level languages are ISA dependent. In fact, it is usually the case that each ISA has only one assembly language.

  • Symbolic Addresses : meaningful symbolic names to memory locations, such as SUM and PRODUCT, rather than use the memory locations’ 16-bit addresses. This makes it easier to differentiate which memory location is keeping track of a SUM and which memory location is keeping track of a PRODUCT.

An Assembly Language Program

  • The translation program is called an assembler, and the translation process is called assembly.
  • In LC-3 ISA, an instruction in assembly language consists of four parts:
  • Label Opcode Operands ; Comment
  • Label* & Comment are optional, Opcode & Operands are mandatory***.

Opcode & Operands

  • The Opcode is a symbolic name for the opcode of the corresponding LC-3 instruction.
  • The number of operands depends on the operation being performed.
  • A literal value must contain a symbol identifying the representation base of the number. We use # for decimal, x for hexadecimal, and b for binary.

Labels

  • Labels are symbolic names that are used to identify memory locations that are referred to explicitly in the program.
  • Label 实际上是给特定内存的一个 alias,因此你可以用它标记 instructions,也可以用它索引 data!
  • In LC-3 assembly language, a label consists of from 1 to 20 alphanumeric characters (i.e., each character is a capital or lower-case letter of the English alphabet, or a decimal digit), starting with a letter of the alphabet except reserved words.
  • There are two reasons for explicitly referring to a memory location:
  • The location is the target of a branch instruction.
  • The location contains a value that is loaded or stored.

Comments

  • The purpose of comments is to make the program more comprehensible to the human reader.
  • It is important to make comments that provide additional insight and do not just restate the obvious.
  • Another purpose of comments is to make the visual presentation of a program easier to understand.

Pseudo-Ops(Assembler Directives)

  • .ORIG: it tells the assembler where in memory to place the LC-3 program. e.g.: .ORIG x3000
  • .FILL: it tells the assembler to set aside the next location in the program and initialize it with the value of the operand. The value can be either a number or a label.
  • .BLKW: it tells the assembler to set aside some number of sequential memory locations(i.e., a BLocK of Words) in the program.
  • .STRINGZ: it tells the assembler to initialize a sequence of n+1 memory locations.

It would result in the assembler initializing locations x3010 through x301D to the following values:

Untitled

  • .END: it tells the assembler it has reached the end of the program and need not even look at anything after it. (In fact, .END does not exist at the time of execution, it is simply a delimiter)

The Assembly Process

Introduction

  • If you have available an LC-3 assembler, you can cause it to translate your assembly language program into a machine language program by executing an appropriate command. In the LC-3 assembler that is generally available via the web, that command is assemble, and it requires as an argument the filename of your assembly language program.
  • eg: assemble solution1.asm outfile

A Two-Pass Process

  • The objective of the first pass is to identify the actual binary addresses corresponding to the symbolic names (or labels). This set of correspondences is known as the symbol table.
  • In pass 1, we construct the symbol table. In pass 2, we translate the individual assembly language instructions into their corresponding machine language instructions.