Understanding Assembly Language: Format, Instructions, and Labels, Slides of Assembly Language Programming

An introduction to assembly language, explaining its role as an intermediate language between high-level programming languages and machine code. It covers the format of assembly language instructions, the use of labels, and the functions of an assembler. The document also touches upon data variables and expression expansion.

Typology: Slides

2011/2012

Uploaded on 07/26/2012

parinita
parinita 🇮🇳

4.8

(6)

67 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
RR
Title goes here 1
Lecture
Lecture 54
Dr Richard Reilly
Dept. of Electronic &
Electrical Engineering
Room 153,
Engineering Building
Assembly Language
Assembly Language
Software usually written in a high level language
C, C++, JAVA, FORTRAN, etc.
Software Compiler
Translates high level code into machine or executable code
i.e. the binary file that is loaded into memory
Machine code provides microprocessor specific binary code
This is decoded and executed to perform a specific task.
Levels of
Levels of Representation
Representation
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
lw $15, 0($2)
lw $16, 4($2)
sw $16, 0($2)
sw $15, 4($2)
0000 1001 1100 0110 1010 1111 0101 1000
1010 1111 0101 1000 0000 1001 1100 0110
1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
ALUOP[0:3] <= InstReg[9:11] & MASK
High Level Language
Program
Assembly Language
Program
Machine Language
Program
Control Signal
Specification
Compiler
Assembler
Machine Interpretation
°
°
Assembly Language
Assembly Language
Machine language programming is very useful for small
programs.
but requires the programmer/digital designer to have an in-depth
knowledge of the specific microprocessor architecture.
Example :
1001 0000 0101 0011 Load Register1 into ACC
0101 1100 1010 0010 Decrement value in Register2
Therefore, the programmer/digital designer is forced to
memorise each machine instruction.
-- or continuously refer to the manual !!
Assembly language is in between a high
level language and machine code
There is a one-to-one correspondence between
each assembly language instruction and each
instruction in the machine code.
•An assembler is used to convert the assembly
language program to machine code.
Assembly Language
Assembly Language
High level languages are designed to be portable
C program on a number of different computers….all should work !!
BUT Assemblers written for specific microprocessors
Intel Pentium, Motorola 56000, AMD K5, etc.
The assembler does a number of tasks for you that makes it
easier to write low-level software.
The assembler makes it look closer to a high level language,
it allows the use of comments, symbolic constants, labels in program
code for loops and jumps.
docsity.com
pf3

Partial preview of the text

Download Understanding Assembly Language: Format, Instructions, and Labels and more Slides Assembly Language Programming in PDF only on Docsity!

Title goes here 1

Lecture 5 Lecture 4

Dr Richard Reilly

Dept. of Electronic &

Electrical Engineering

Room 153,

Engineering Building

Assembly Language Assembly Language

  • Software usually written in a high level language
    • C , C++, JAVA, FORTRAN, etc.

• Software Compiler

  • Translates high level code into machine or executable code
    • i.e. the binary file that is loaded into memory
  • Machine code provides microprocessor specific binary code
  • This is decoded and executed to perform a specific task.

Levels of Levels of RepresentationRepresentation

temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;

lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2)

0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111

ALUOP[0:3] <= InstReg[9:11] & MASK

High Level Language Program

Assembly Language Program

Machine Language Program

Control Signal Specification

Compiler

Assembler

Machine Interpretation

° °

Assembly Language Assembly Language

Machine language programming is very useful for small programs. but requires the programmer/digital designer to have an in-depth

knowledge of the specific microprocessor architecture.

Example : 1001 0000 0101 0011 Load Register1 into ACC 0101 1100 1010 0010 Decrement value in Register

Therefore, the programmer/digital designer is forced to memorise each machine instruction. -- or continuously refer to the manual !!

• Assembly language is in between a high

level language and machine code

  • There is a one-to-one correspondence between

each assembly language instruction and each

instruction in the machine code.

  • An assembler is used to convert the assembly

language program to machine code.

Assembly Language Assembly Language

  • High level languages are designed to be portable ⇒ C program on a number of different computers….all should work !!

BUT Assemblers written for specific microprocessors

  • Intel Pentium, Motorola 56000, AMD K5, etc.
  • The assembler does a number of tasks for you that makes it easier to write low-level software.
  • The assembler makes it look closer to a high level language,
  • it allows the use of comments , symbolic constants , labels in program code for loops and jumps.

Title goes here 2

Format of an Assembly Language Format of an Assembly Language

InstructionInstruction

• The program divided into 4 columns or fields :

  • label field, opcode field, operand field, comment field.

1003 ADD $2 $4 ;Add 2+4 to ACC

  • OPCODE is the operation the processor is to perform.
    • It forms a code for the operation, hence OPCODE
  • Some processors have only 20 or 30 opcodes,
    • other have hundreds.

Example ofExample of OpcodesOpcodes

ADD add ANDI AND immediate MUL multiply JMP jump/goto CMP compare

Each instruction takes 0, 1, 2 or 3 operands (rarely more than 3).

  • The operand is either a
    • constant (e.g. a data value)
    • A program address (c.f. Stored Program Concept : Von Neumann)
    • A register.

OPERANDSOPERANDS

Usually we can consider an operand to be one of the following:

  • Binary Constant - Data Value
  • Data Memory Address - Variable
  • Internal Register
  • Internal Register as Pointer to Data Memory

Address

  • Program Memory Address

For each line of assembly language a LABEL is optional.

  • If used, the assembler will substitute any occurrences of LABEL in the rest of the program to the value of program location (e.g. in a jump instruction).

Assembly Language ConventionsAssembly Language Conventions

  • Various conventions used by assemblers to specify

HEX numbers, constants etc.

  • use the following conventions (Motorola like).
  • Assume all numbers are decimal
  • Use $ to specify a HEX number, e.g. $B = 11
  • Use # to specify a constant, e.g. #
  • Use register names of Rn , e.g. R2 or ACC for Accumulator
  • Use @ to specify indirect addressing
    • register is used as a pointer

• Use ; to indicate rest of line is a comment

Assembly Language Assembly Language

FunctionsFunctions

  • As well as converting each instruction to machine code the assembler does the following tasks. 1. Symbolic Substitution
  • The assembler allows the use of symbols or names (like #DEFINE in C) which it converts to binary constants. - Allows for easier programming and ease of understanding. - Usually symbols defined at the top of the file. TEN EQU 10 THRESHOLD EQU $

Hence the following would be converted as, ANDI TEN : ANDI # CMP #THRESHOLD : CMP #$

Assembly Language Assembly Language

2. Program Code Location and DATA Memory Location

  • The assembler allows you to specify location at which the program code should start and location where the data variables should start. Example ORG_PROG #$1000 ;Following instructions start at location $ ORG_DATA #$2000 ;Data variables start at location $ Program Memory

$

$

MEMORY

$

$

Program Memory

Data Memory

Data Memory

MEMORY