Understanding Machine Language: A Simple Machine Example, Slides of Computer Architecture and Organization

An introduction to machine language and assembly language programming through the example of a simple machine. It covers the use of registers, data transfer and processing instructions, and the assembly process. Students of computer science or engineering may find this useful for gaining a deeper understanding of low-level programming and computer architecture.

Typology: Slides

2011/2012

Uploaded on 07/15/2012

sachine
sachine 🇮🇳

2.5

(2)

49 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 3
Assembly Language
Programming
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Understanding Machine Language: A Simple Machine Example and more Slides Computer Architecture and Organization in PDF only on Docsity!

Chapter 3

Assembly Language Programming

A Simple Machine (Objective)

We will try to understand theuse of Machine Language bydesigning a simple machinewith the given parameters asdefined in the next pages

A Simple Machine…



This simple processor supports threetypes of instructions:

■ data transfer, ■ data processing, and ■ program control. 

The data transfer operations are:

■ load, ■ store, and ■ move data between the registers AC(Accumulator) and DR (Data Register).

A Simple Machine…



The data processing instructions are:

■ add, subtract, and, and not. 

The program control instructions are:

■ jump and conditional jump. 

The instruction size is 16 bits:

■ 4 bits for the operation code and 12 bits forthe address.

A Simple Machine…(Instruction Set)

Jump to instruction on adr if AC = adr 1010 Jump to instruction with address adr adr 1001 Complement contents of AC 1000 AND bitwise DR to AC 0111 Subtract DR from AC 0110 Add DR to AC 0101 Copy the contents DR to AC 0100 Copy the contents AC to DR 0011 Store contents of AC into memory (location adr). adr 0010 Load operand from memory (location adr) into AC adr 0001 Stop execution 0000 Meaning of Instruction Operand Op Code

A Simple Machine … (Simple Machine

Language Program in Binary)

Data Value is 0 0000 0000 0000 0000 0000 0001 0000 Data Value is 96 0000 0000 0110 0000 0000 0000 1110 Data Value is 350 0000 0001 0101 1110 0000 0000 1100 Stop 0000 0000 0000 0000 0000 0000 1010 Store contents of AC in location 16 0010 0000 0001 0000 0000 0000 1000 Add DR to AC 0101 0000 0000 0000 0000 0000 0110 Load the contents of location 14 intoAC 0001 0000 0000 1110 0000 0000 0100 Move contents of AC to DR 0011 0000 0000 0000 0000 0000 0010 Load the contents of location 12 inAC 0001 0000 0000 1100 0000 0000 0000 Description Binary Instruction Memory Location

Instruction Mnemonics and

Syntax

 Assembly programs are written with shortabbreviations called mnemonics.  A mnemonic is an abbreviation thatrepresents the actual machine instruction.  Assembly language programming is thewriting of machine instructions in mnemonicform, where each machine instruction isreplaced by a mnemonic.  Clearly the use of mnemonics would makeprogramming at this low level easier and moremanageable.

Instruction Mnemonics and Syntax  An assembly program consists of a sequenceof assembly statements.  Each line of an assembly program is split intothe following four fields: ■ label, ■ operation code (opcode), ■ operand, and ■ comments. Comment(Optional) Operand (Required in some instructions Operation Code (Required) Label (optional)

A Simple Machine … (

Instruction Mnemonics and Syntax

AND bitwise DR to AC AND Complement the contents of AC NOT Jump to instruction adr if AC = 0 adr BZ Jump to instruction with address adr adr BRA Subtract DR from AC SUB Add DR to AC ADD Copy the contents of DR to AC MOV Copy the contents of AC to DR. MOVAC Save contents of AC in memory (location x). x ST Load operand from memory (location x) into AC. x LD Stop Execution STOP Meaning of Instruction Operand Mnemonics

Assembler Directives and Commands

 Assembler directives are commands that areunderstood by the assembler and do notcorrespond to actual machine instructions.  Assembler directives are commands that areunderstood by the assembler and do notcorrespond to actual machine instructions.  In assembly language programs symbols areused to represent numbers in order to makethe code easier to read, understand, anddebug.

Assembly and Execution of Programs  A program written in assembly language needs to betranslated into binary machine language before it canbe executed.  Three steps exist in the assembly and executionprocess. ■ The assembler reads the source program in assemblylanguage and generates the object program in binary form.The object program is passed to the linker. ■ The linker will check the object file for calls to procedures inthe link library. The linker will combine the requiredprocedures from the link library with the object program andproduce the executable program. ■ The loader loads the executable program into memory andbranches the CPU to the starting address. The programbegins execution.

Assembly and Execution of Programs

 Assemblers ■ A simple assembler scans the entire assemblyprogram twice, where each scan is called a pass. ■ During the first pass, it generates a table thatincludes all symbols and their binary values. Thistable is called the symbol table. ■ During the second pass, the assembler will usethe symbol table and other tables to generate theobject program, and output some information thatwill be needed by the linker

Assembly and Execution of Programs

 Data Structures ■ The assembler uses at least three tables toperform its functions:

  • symbol table: is generated in pass one, has an entry for every symbol in the program. - opcode table: provides information about the operation codes. Associated with each symbolic opcode in thetable are its numerical value and other information aboutits type, its instruction length, and its operands. - pseudo instruction table: Each entry refers the assembler to a procedure that processes the pseudoinstruction when encountered in the program.

Assembly and Execution of Programs