Introduction To Assembly

  • Uploaded by: jhe04
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Introduction To Assembly as PDF for free.

More details

  • Words: 1,643
  • Pages: 22
Introduction to Assembly Language

Bits and Bytes Bits – fundamental building block of computer storage. It is a contraction of the compound word “binary digit”



Bytes – each group of 8 related bits. It is the basic unit of binary information.



Related bytes

08/06/09



2

Integer Representation 08/06/09

Sign-magnitude – the leftmost bit is the sign bit ; the most significant bit (MSB)  Ones’ complement – negation of the number is obtained by inverting each of its bits  Two’s complement – the negation of the number is obtained by inverting each of its bits then adding 1 to the resulting bit pattern 

3

ASCII 08/06/09

To get information in and out of the computer, we need to use numbers, letters and other symbols. This implies some kind of alphanumeric code for the I/O unit of a computer  American Standard Code for Information Interchange 

4

ASCII Table 08/06/09

5

Registers 08/06/09



General Purpose Registers AX register – sometimes called as the accumulator. This is used in input, output and arithmetic operations AX = 8035h  AH = 80h  AL = 35h 

BX Register – also known as the Base Register. It is also used for computations since it is the only general purpose register that can be used to extend addressing BX = 0C05h  BH = 0Ch  BL = 05h 

6

Registers 08/06/09



General Purpose Registers CX register – referred to as the counter register. This is used with certain instructions that perform operations repeatedly. It can also be used for computations CX = B1F2h  CH = B1h  CL = F2h 

DX register – also known as data register. It is used to hold data for any purposes. Some I/O operations and multiply/divide operations that involve large values require its use DX = 0BEAh  DH = 0Bh  DL = EAh 

7

Registers 08/06/09



Pointer Registers BP register – this 16-bit base pointer register facilitates referencing parameters, which are the data, and addresses that a program passes through the stack IP register – this 16-bit instruction pointer register contains the offset address of the next instruction that is to execute. It is associated with the CS register in that the IP indicates the current instruction within the currently executing code segment SP register – this 16-bit stack pointer provides an offset value which when associated with the SS register, refers to the current word being processes in the stack.

8

Registers 08/06/09



Segment Registers CS register – CODE SEGMENT register contains the starting address of a program’s code segment. This segment address plus an offset value in the IP register indicates the address of an instruction to be fetched for execution DS register – DATA SEGMENT register contains the starting address of a program’s data segment. Instructions use this to locate data ES register – EXTRA SEGMENT register is used by some string operations to handle memory addressing. SS register – STACK SEGMENT register permits the implementation of a stack in memory that a program uses for temporary storage of addresses

9

Registers Index Registers – these are registers available for indexed addressing and addition/subtraction operations

08/06/09



SI register – the 16-bit SOURCE INDEX register is required for some string operations. It is associated with the DS register DI register – the 16-bit DESTINATION INDEX register is also required for some operations and is associated with the ES register.

10

Registers Flag Registers – these are special registers that indicate the present status of the computer and the results of processing

08/06/09



Overflow flag (OF) – it indicates that the result of an operation is too long to be stored in the destination operand; OV is displayed if there is an overflow; NV is displayed for no overflow mov al, 04 add al, 7f int 20

Direction flag (DF) – it is used in string operations to determine the direction of data transfer. UP is displayed for upward direction; DN is displayed for downward direction

11

Registers 08/06/09

Interrupt Flag (IF) – it indicates that all external interrupts such as keyboard entry are to be processed or ignored. EI is displayed for enable interrupt; DI for disabled interrupt mov ah, 02 mov dl, 41 int 21 int 20

Sign Flag (SF) – indicates that the result of an operation is positive or negative. PL for plus and NG for negative mov al, 03 sub al, 08 int 20

12

Registers 08/06/09

Zero Flag (ZF) – it indicates whether an operation produced a zero result. ZR is displayed for zero; NZ for nonzero. mov ax, 0008 sub ax, 0008 int 20

Auxiliary Flag (AF) – similar to carry flag except that it indicates the presence or absence of a carry or borrow based on 4-bit numeric representation in bits. NA for no auxiliary carry; AC for auxiliary carry mov al, ff sub al, 01 int 20

13

Registers 08/06/09

Parity Flag (PF) – it indicates whether the result of an operation contains an even number or odd number of 1s. PE is displayed for parity even; PO for parity odd Mov al, 08 Add al, 02 Int 20

Carry Flag (CF) – it indicates whether the instructions produced a value that can be too big ( or too small) to be held in the specified register or memory location. CY for carry; NC for no carry mov al, ff sub al, 01 int 20

14

Debug 08/06/09

Bug – computer technology for error or mistake in a program or computer system  Debugging – is a methodological process of finding and reducing the number of bugs or defects in a computer program  Debugger –is a program tool that provides an environment for testing load modules. Load modules are executable files that can have extensions of .COM and .EXE  Debug – is a software that is classified as debugger which is used for testing and debugging executable programs 

15

Advantages of debug It It It It



is free. is universally available. is simple to use. requires relatively little memory.

08/06/09



Rules of debug command It is not case-sensitive. It assumes that all numbers given are in hexadecimal format. You can enter a space only when it is needed to separate parameters of a particular command. 16

Debug commands 08/06/09

Q (Quit) – finishes the debug session and exits back to DOS environment  H( Hexarithmetic) – shows the sum and difference of two 4-digit hexadecimal numbers, coded as H  R(Register) – allows you to display all registers and their values. It also shows the next instruction and permits you to change the value of a particular register.  E (Enter) – enables you to key in data or machine instructions into memory beginning at a specific location address 

17





  



08/06/09



D (Display or Dump) – displays the contents of a portion memory in hex and ASCII forms starting with the given address A(Assemble) – allows you to create program in mnemonic or symbolic code. It also translates this assembly T( Trace) – runs the program in single-step mode. It also displays the new values of the registers and the next instruction to be executed. G(Go) – runs the program as a whole in memory and displays the output U(Unassemble) – lists all the instructions contained in the program beginning at the given address N(Name) – Gives a name to your program, coded as N <path> . The base name of the filename must be eight characters long and the extension name is .COM W(Write) – saves the program onto the disk storage

18

Basic Assembly Instruction used in Debug Mov (move data) – it copies and transfers data between two registers, or between an immediate data to a register

08/06/09



Mov , Mov , mov ax, bx mov cx, 5083 

Add (add data) – it is used to get the sum of two registers or a register and an immediate data, and stores the result to the left most register Add , Add , add cx, bx add ax, 0308

19

Basic Assembly Instruction used in Debug SUB(subtract data) – it is used to get the difference of two registers or a register and an immediate, and stores the result to the left most register

08/06/09



sub , sub , sub cx, bx sub ax, 0308 sub al, bl 

MUL (multiply data) – it is used to get the product of a given register and AX register, and stores the result to AX register. If the product is greater than 16 bits, the overflow is stored in DX register  

mul mul cx

20



DIV (divide data) – it is used to divide the value of a given register and AX register, and stores the quotient to AX and the remainder to DX registers respectively 

DIV div bx

INC (increment by one) – it is used to increase the value of the register by one 

inc

08/06/09



inc ax 

DEC(decrement by one) – the opposite of INC, instead of increasing, it decreases the value of the register by one 

dec dec ax



Loop (loop until complete) – it controls the execution of a program segment in a specified number of times. The CX register should contain a count value before starting the loop and automatically decrements by one. If CX register is not equal to zero, it transfers to its operand address which points to the start of the loop, otherwise it drops through the next instruction 

loop loop 0108

21

08/06/09

Seatwork...

22

Related Documents


More Documents from ""