assembly language – 1. 1. machine language this is what the computer actually sees and deals with....

21
Assembly Language – 1

Upload: christopher-carroll

Post on 26-Mar-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Assembly Language – 1

Page 2: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

1. Machine Language

This is what the computer actually sees and deals with. Every command the computer sees is given as a number or sequence of numbers.

2. Assembly Language

This is the same as machine language, except the command numbers have been replaced by letter sequences which are easier to memorize. Other small things are done to make it easier as well.

3. High-Level Language

They are there to make programming easier. Assembly language requires you to work with the machine itself. High-level languages allow you to describe the program in a more natural language. A single command in a high-level language usually is equivalent to several commands in an assembly language.

Page 3: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

To study… - SELF-study• Syntax

• Variables

• Basic data movements and arithmetic instructions

• Program organization – comprising code, data & stack• Assembly lang prog MUST be converted to a machine lang

prog before it can be executed by an assembler

Page 4: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

1. Syntax

• Assembly lang – low-level programming language

• An assembly language is specific to a certain computer architecture, in contrast to most high-level programming languages, which generally are portable to multiple systems.

Page 5: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Assembler

• Assembly language programs are converted into executable machine code by a utility program referred to as an assembler, the conversion process being referred to as assembly or assembling the program.

• Assembler Microsoft Macro Assembler [MASM]

Page 6: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Assembly lang

• A program written in assembly language consists of a series of (mnemonic) processor instructions and meta-statements (known variously as directives, pseudo-instructions and pseudo-ops), comments and data.

• Assembly lang. instructions usually consist of

an opcode mnemonic

followed by a list of data, arguments or parameters.

These are translated by an assembler into machine language instructions that can be loaded into memory and executed.

Page 7: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

name operationoperand(s) ;comment

START:MOV CX, 5 ;যা� ইচ্ছা�

লি�খ! ‘;’ লি�ও!

Page 8: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Example

• The instruction that tells an x86 processor to move an immediate 8-bit value into a register.

• The binary code for this instruction: 10110

• followed by a 3-bit identifier for which register to use. The identifier for the AL register is 000, so the following machine code loads the AL register with the data 01100001.

Page 9: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

10110 000 01100001Instruction AL data

B0 61Instruction AL data

In HEX

-Intel assembly language provides the mnemonic MOV (an abbreviation of move) for instructions such as this-so the machine code above can be written as follows in assembly language, complete with an explanatory comment if required, after the semicolon.

MOV AL, 61h ; Load AL with 97 decimal (61 hex)

Page 10: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

• The Intel opcode 10110000 (B0) copies an 8-bit value into the AL register,

• while 10110001 (B1) moves it into CL

• 0110010 (B2) does so into DL. MOV AL, 1h ; Load AL with immediate value 1

MOV CL, 5h ; Load AL with immediate value 5

MOV DL, 3h ; Load AL with immediate value 3

Page 11: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

• Transforming assembly language into machine code is the job of an assembler, and

• The reverse can at least partially be achieved by a disassembler.

MOV EAX, [EBX] ; Move the 4 bytes in memory at the address contained in EBX into EAX

MOV [ESI+EAX], CL ; Move the contents of CL into the byte at address ESI+EAX

Page 12: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

• Each computer architecture has its own machine language. • Computers differ in the number and type of operations

they support, in the different sizes and numbers of registers, and in the representations of data in storage.

• While most general-purpose computers are able to carry out essentially the same functionality, the ways they do so differ; the corresponding assembly languages reflect these differences.

Page 13: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

.section .data• Anything starting with a period isn’t directly translated into

a machine instruction.

• Instead, it’s an instruction to the assembler itself. These are called assembler directives or pseudo-operations because they are handled by the assembler and are not actually run by the computer.

• The .section command breaks your program up into sections.

• This command starts the data section, where you list any memory storage you will need for data

Page 14: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

.section .text

which starts the text section. The text section of a program is where the program instructions live.

Page 15: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

.globl _start• This instructs the assembler that _start is important

to remember. • _start is a symbol, which means that it is going to be

replaced by something else either during assembly or linking.

• Symbols are generally used to mark locations of programs or data, so you can refer to them by name instead of by their location number

Page 16: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

_start:

• It defines the value of the _start label. A label is a symbol followed by a colon.

• Labels define a symbol’s value. When the assembler is assembling the program, it has to assign each data value and instruction an address. Labels tell the assembler to make the symbol’s value be wherever the next instruction or data element will be.

• This way, if the actual physical location of the data or instruction changes, you don’t have to rewrite any references to it - the symbol automatically gets the new value.

Page 17: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Next is instruction!

• MOV

• ADD

• .

• .

• .

Page 18: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Just a recap – Imp –

on 8086 processor

Page 19: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

8086 Internal Configuration

Page 20: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number

Simplified block diagram over Intel 8088 (a variant of 8086); 1=main registers; 2=segment registers and IP; 3=address adder; 4=internal address bus; 5=instruction queue; 6=control unit (very simplified!); 7=bus interface; 8=internal data bus; 9=ALU; 10/11/12=external address/data/control bus

Page 21: Assembly Language – 1. 1. Machine Language This is what the computer actually sees and deals with. Every command the computer sees is given as a number