17
First part System Utilities Lecture 3 ASSEMBLER Ştefan Stăncescu 1

First part System Utilities Lecture 3 ASSEMBLER Ştefan Stăncescu 1

Embed Size (px)

Citation preview

First partSystem Utilities

Lecture 3

ASSEMBLER

Ştefan Stăncescu

1

ASSEMBLER

von Neumann architecture :

Stored program computer (H/W): CPU(ALU+REG+PC+CPU_CTRL) + MEM + I/O

Shared memory <= data + code (program) all in binary

CPU(H/W) works only on a dedicated instruction set

Object program:

list of activities carried out by the CPU and rest of H/W

list of simple CPU instructions, all in binary

=> flexibility by creative lists of fixed instructions

=> complex activities => complex applications

2

ASSEMBLER

Flexibility => changing the list of microinstruction - binary

(running different programs on same H / W)

Program object (S/W - in binary)

directly controls the machine (vN)

for a given (complex) application

Application on the vN machine

“code” processes "data" - in binary

in same memory space - in binary

takes data in => data out - in binary

ALL BINARY3

ASSEMBLER

The human programmer - creator of useful applications

Originally used binary model (1/0) of vN architecture

for the faithful exact copy of the H/W vN machine

=> machine language.

difficult to understand even for simple programs.

For readability, another vN machine model, abstract (MV?)

w/human readable signs:

literal mnemonic for instructions op-codes

alphanumerical identificators (+-*/ operators, :; etc. )

=> assembly language

Between the two languages - bi-univocal correspondence

4

ASSEMBLER

Source program – solution representation of some problem

draft list of standardized CPU intelligible activities

organized as a list of H/W instructions of the vN machine

A program line format => instruction mnemonic + operands

strongly attached to the H/W structure of vN machine

Assembly language:

mechanism of solutions representation

with mnemonic instructions ("opcode")

with literal representation of H/W circuit activity

human understandable - the first level of abstraction5

ASSEMBLER

Assembling a source program to machine language

=> automatic operation of passing from

literal representation of mnemonic instructions to

binary representation of instructions

Human intelligibility (literal A-Z a-z 1-9 + / * -., “ etc.).

to machine intelligibility (vN machine - binary - 1/0)

Assembler – S/W system utility that automate assembling

automatically translate - source files => object files

(+ additional means of development - list, sym, etc)

6

ASSEMBLER

Format type of one line from assembly source file language :

tag: op-code operands ;comment

Essential operation of an assembler:

converting

source file (lines of characters) to

object file (their equivalent binary representation)

Adjacent lines in the source file =>

=> adjacent bytes in object file

Result of assembly = binary representation of the solution

= vN machine understandable (executable) =

= the "object" file (program in “image memory”) .7

ASSEMBLER

The “data” in assembly language

data structures varying in sizes and structure

ex. complex structures - strings, arrays, etc.

Assembler invents for them and for programmer help,

operations that not exist in H/W, called

“pseudo instructions” or “pseudo functions”

as abstract maneuvers, operations that not exist in H/W,

facilities of programming, addressing, etc. called

“directives”

8

ASSEMBLER

PSEUDOFUNCTION THE EFFECT ON OBJECT PROGRAM ASSEMBLED

DB Defines the contents of memory byte

DW Defines the contents of memory word

RESB Assign a save space of memory, in bytes

RESW Assign a save space of memory, in words

EQU Defines a symbolic name for a constant

START Sets the module name and first address, as the initial reference

END Sets the end program and start address

ORG Sets a new address as new reference address

SECT Sets current section

9

ASSEMBLER

NAME OF DIRECTIVE THE EFFECT ON OBJECT PROGRAM ASSEMBLED

BIT Sets the word length in 8/16/32/64 bits

MODEL Sets the dimensions for the sections address spaces

PUBLIC Sets variables defined for external modules

EXTERN Sets variables defined in external modules

INCLUDE Include another source program in current program

INCLB Include another binary file in currently object file

IF/ENDIF Defining a group of lines conditionally assembled

10

ASSEMBLER

Object files are intermediate products of assemblers

Object file formats are

data structures for machine code loaders

intended to be processed by the link-loaders as

system utilities dedicated for

loading in machine physical memory and for

starting the corresponding process as active

solution from the initial program source

Auxiliary formats and products: list file, symbol list, etc.

for interactive operations as development, debug, test, etc.

11

ASSEMBLER Object format

12

Name No. crt. byte Meaning field

Start(S)

1 Field code character “S"

2-9 Program Name

10-13 Address in memory for first stripe load

14-15 Length in bytes for all program code

Content(C)

16 Field code character "C"

17-18 Beginning address of the current paragraph

19-20 Current paragraph length

21-148 A stripe of object code, H/W executable (128 bytes as example)

149-??? Repeating area 17-148

End(E)

???+1 Field code character "E"

???+2 – ???+3 Address of the first instruction to be executed, start address

???+4 EOF, (end of file)

ASSEMBLER Data structures of one assembler

OPTAB op-codes table

R/O table with symbolic names (mnemonics) of microinstructions fixed by the structure of H/W (uP).

SYMTAB symbolic names table,

R/W table, with attributes of the symbols and names invented by programmer or deducted from solution program, with content specific for each application

determined by the programmer imagination;

table fulfilled before binary conversion by

scanning the source file and

finding the names invented by programmer.

LOCCTR instruction location memory counter

13

ASSEMBLER First pass

14

ASSEMBLER Operations performed in the first assembler pass

• setting addresses in the memory space of the CPU for all source program instructions using LOCCTR;

• setting addresses LOCTTR labels and save them in SYMTAB;

• calculation expressions that define symbols;

• fulfillment of directives as RESB, RESW, DB, DW;

• implementation of the amending directives of the current address in the program with LOCCTR;

• grammatical control of the source file in accordance with assembly language grammar used in reporting errors.

15

ASSEMBLER Second pass

16

ASSEMBLER Operations performed in the second assembler pass

• translate the mnemonic instructions into machine code using OPTAB;

• operands calculation in expressions, replacing the symbols with attributes from SYMTAB;

• generate data according to directives DB, DW;

• execution of other directives;

• format the obtained file object as a standard format suitable to linker and loader;

• format the listing file with information required for documentation and debugging the program, including addresses, conversions, assembly error codes, etc.

17