Professional Documents
Culture Documents
Assembly Language
Assembly language: Assembly language is used for most programming because it is extremely difficult to program a microprocessor in its native, that is hexadecimal machine language. Assembler: An assembler is a program that converts software written in symbolic machine language (the source programme) into hexadecimal machine language (object programme). The primary reason to use assembler is because development and modification are always difficult in machine language.
BH
CH DH
BL
CL DL
C. Vongchumyen 12 / 2003
Special Register BP Base Pointers register SI Source Index register DI Destiny Index register SP Stack pointer register IP Next Instruction Pointer register F Flag register O, D, I, T, S, Z, A, P, C
C. Vongchumyen 12 / 2003
Flag Register
OF DF IF TF SF ZF AF PF CF
11 10
OF DF IF TF SF ZF AF PF CF
Over Flow Direction Interrupt Trap Sign Zero Auxiliary Parity Carry
Over flow from arithmetic Inc or Dec for moving or compare string Enable or Disable all external interrupt Enable or Disable single step operation Sign bit for arithmetic number, 1 = negative Result is zero Carry out for bit 3 on 8-bit data Even or Odd parity of low-order, 8-bit data Carry out from MSB, Left most of arithmetic
C. Vongchumyen 12 / 2003
Addressing Mode
Register
Immediate
MOV CX,DX
MOV AL,22h
Direct
MOV CX,[1234h]
Assembly Template
Page 60,132 Title Exasm1 skeleton of an assembly Program ; -----------------------------------------------------------STACKSG Segment Para stack 'Stack' STACKSG Ends DATASG DATASG CODESG Begin Assume mov mov mov int Begin CODESG Segment Para 'Data' Ends Segment Para 'Code' Proc far CS:CODESG, DS:DATASG, SS:STACKSG ax,DATASG ds,ax ... ax,4C00h 21h endp Ends Begin
End
C. Vongchumyen 12 / 2003
Assembly Template
Page 60,132 60 Lines per page 132 Character per line on listing file ( .LST )
Title Exasm1 skeleton of an assembly Program This text will show on every page of listing file
C. Vongchumyen 12 / 2003
Assembly Template
STACKSG Segment Para Defining Stack Segment . STACKSG Ends Name
Alignment : Para Combine : Stack Class Type : Stack
stack 'Stack
C. Vongchumyen 12 / 2003
Assembly Template
DATASG Segment Defining Data Segment . DATASG Ends
CODESG Segment Defining Code Segment . CODESG Ends
Para 'Data
Para 'Code
C. Vongchumyen 12 / 2003
Assembly Template
Begin Assume mov mov Begin ... endp Proc far CS:CODESG, DS:DATASG, SS:STACKSG ax,DATASG ds,ax
Far
C. Vongchumyen 12 / 2003
Assembly Template
Set Program Entry Point End Begin
ax,4C00h 21h
Using Dos Interrupt Function 4CH Return 00H as exit code to DOS
C. Vongchumyen 12 / 2003
.CODE
ORG 100H mov mov mov int end
Computer Organization and Assembly Language #2 C. Vongchumyen 12 / 2003
TINY
Small
Compact
64 KB
64 KB 64 KB
64 KB Each 64 KB Each 64 KB Each
64 KB
64 KB 128 KB 640 KB 640 KB 640 KB 640 KB
C. Vongchumyen 12 / 2003
C. Vongchumyen 12 / 2003
Set Address of Data segment Mov ax,@data Mov ds,ax ORG 100H First Op-Code locate at Offset 100H ( Required for .COM File )
C. Vongchumyen 12 / 2003
C. Vongchumyen 12 / 2003
.OBJ
.EXE
C:\TASM\BIN>TLINK test Turbo Link Version 5.1 Copyright (c) 1992 Borland International
C. Vongchumyen 12 / 2003
.CODE
ORG 100H mov mov mov int ax,@data ds,ax ax,4C00h 21h
ax,@data ds,ax
ax,4C00h 21h Warning: No stack
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : MOV Purpose : Data transfer between memory cells, registers and the accumulator. Syntax : MOV Destiny, Source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : LEA Purpose : Syntax : To load the address of the source operator LEA destiny, source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : LAHF Purpose : It transfers the content of the flags to the AH register Syntax : LAHF
Example :
LAHF
This instruction is useful to verify the state of the flags during the execution of our program
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : POP Purpose : It recovers a piece of information from the stack Syntax : POP destiny
Example :
POP AX
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : POPF Purpose : Syntax : It extracts the flags stored on the stack POPF
Example :
POPF
BIT FLAG 0 CF, 2 PF, 4 AF, 6 ZF, 7 SF, 8 TF, 9 IF, 10 DF, 11 OF
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : PUSH Purpose : Syntax : Example : It places a word on the stack PUSH source PUSH AX
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : PUSHF
Purpose : It places the value of the flags on the stack.
Syntax :
Example :
PUSHF
PUSHF
This command decreases by 2 the value of the SP register and then the content of the flag register is transferred to the stack, on the address indicated by SP. The flags are left stored in memory on the same bits indicated on the POPF command.
Computer Organization and Assembly Language #2 C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : AND
Purpose : It performs the conjunction of the operators bit by bit. Syntax : AND destiny, source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : NEG
Purpose : It generates the complement to 2.
Syntax :
Example :
NEG destiny
NEG AX
For example, if AX stores the value of 1234H, then: NEG AX This would leave the 0EDCCH value stored on the AX register.
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : NOT Purpose : It carries out the negation of the destiny operator bit by bit. NOT destiny
Syntax :
Example :
NOT AX
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : OR
Purpose : Syntax : Example : OR OR Logic inclusive OR OR destiny, source OR AX,0FF00H AX,BX AX,[BX]
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : XOR
Purpose : Syntax : Logic exclusive OR XOR destiny, source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : TEST
Purpose : Syntax : It logically compares the operators TEST destiny, source
Example : TEST AX,0FF00H TEST AX,BX TEST AX,[BX] It performs a conjunction, bit by bit, of the operators, but differing from AND, this instruction does not place the result on the destiny operator, it only has effect on the state of the flags.
Computer Organization and Assembly Language #2 C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : ADC Purpose : Syntax : addition with carry ADC destiny, source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : ADD Purpose : Syntax : addition without carry ADD destiny, source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : DIV Purpose : Syntax : Example : Division without sign. DIV source DIV BL ( 8 Bit ) AL = AX / BL AH = Remainder BX ( 16 Bit ) AX = DX:AX / BX DX = Remainder
C. Vongchumyen 12 / 2003
DIV
Basic Instruction
Instruction : IDIV Purpose : Syntax : Division with sign. IDIV source
Example : IDIV BL ( 8 Bit ) IDIV BX ( 16 Bit ) basically consists on the same as the DIV instruction, and the only difference is that this one performs the operation with sign. For its results it used the same registers as the DIV instruction.
Computer Organization and Assembly Language #2 C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : MUL Purpose : Syntax : Example : Multiplication without sign. MUL source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : IMUL Purpose : Syntax : Example : Integer Multiplication with sign. IMUL source
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : SUB Purpose : Syntax : Example : SUB SUB subtraction without carry SUB destiny, source SUB AX,0FF00H AX,BX AX,[BX]
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : SBB Purpose : Syntax : Example : SBB SBB subtraction without borrow SBB destiny, source SBB AX,0FF00H AX,BX AX,[BX]
C. Vongchumyen 12 / 2003
Basic Instruction
Instruction : SBB Purpose : Syntax : Example : SBB SBB subtraction without borrow SBB destiny, source SBB AX,0FF00H AX,BX AX,[BX]
C. Vongchumyen 12 / 2003