1/2002jnm1 positional notation (hex digits). 1/2002jnm2 problem the 8086 has a 20-bit address bus....
TRANSCRIPT
1/2002 JNM 1
Positional Notation (Hex Digits)
1/2002 JNM 2
Problem
• The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory. How many bits and how many HEX digits are required to access 1M memory?
• 2N = 1M (where N is in bits)
• N = 20 bits = 20/4 = 5 HEX digits
1/2002 JNM 3
Memory Map for an 80x86 computer running MS-DOS
1/2002 JNM 4
The memory space of the 8086 consists of 1,048,576 bytes or 524,288 16-bit words.
1 MB Memory Space of 8086
1/2002 JNM 5
Within the 1 MB of memory, the 8086 defines 4 64KB memory blocks.
Segmented Memory
7FFFF
The segment registers point to location 0 of each segment. (The base address)
DS: E000 CS: B300
SS: 7000 ES: 5D27
1/2002 JNM 6
Assembly Language Statements
Instructions - Executable Statements
Directives – provide information to assembler about how to generate executable code
Format -
[name] [mnemonic] [operands] [;comment]
1/2002 JNM 7
Names
• Max 247 characters (MASM)
• No distinction between uppercase, lowercase letters.
• First character can be a letter, ‘@’, ‘_’, ‘$’
• Cannot use an assembler reserved word.
• Identify labels, variables, symbols, keywords
1/2002 JNM 8
OP Codes and Operands
Op-code destination operand, source operand
HLT ; zero operandsINC AX ; one operandMOV AX, 100 ; two operandsSHLD DX, AX, 4 ; three operands
1/2002 JNM 9
AL 00
Immediate Addressing Mode
Mov AL, 3CH
AL 3C
1/2002 JNM 10
Register Addressing Mode
Mov AL, BL
AL 00BL 4D
AL 4DBL 4D
1/2002 JNM 11
Direct Addressing Mode
0023 12
0022 34
0021 56
0020 78
Mov CL, [0020H]
Mov CX, [0020H]
Memory (data)
Little Endian Format – The “little” end of the number is stored first.
CL 78
CX 5678
Mov ECX, [0020H]ECX 12345678
1/2002 JNM 12
Register Indirect Addressing Mode
location
0023 12
0022 34
0021 56
0020 78Mov CL, [SI]
In the 8086, only BX, BP, SI and DI may be used as memory pointers. Later processors don’t have this restriction.
Mov SI, 0022H
CL 34
SI 0022
1/2002 JNM 13
BX 0020
Base + Displacementlocation
0023 12
0022 34
0021 56
0020 78Mov AL, [BX +2]
Useful when accessing individual elements in an array. Note that the array begins with element 0, element 2 corresponds to the third location in the array. The displacement corresponds to byte offset from the base, not element number in the array.
Mov BX, 0020H
AL 34
1/2002 JNM 14
BX 0020
Base + Index + Displacement(Useful when accessing individual elements in an record)
Mov BX, 0020H ;BX points to record starting address
SI 000C
Mov SI, 000CH ;SI points to record three (4 elements ;per record x 3 records = 000C)
Mov AL, [BX+SI+1] ;AL now has the data in element 1 of ;record #3 (assumes elements are 1 byte)
1/2002 JNM 15
• Base + Displacement
– Mov AL, [BX + 4]
• Base + Index + Displacement
– Mov AL, [BX+SI+3]
• Base + Index*Scale + Displacement
– Mov AL,[BX+SI*4+3]
• Immediate
– Mov AL, 4CH
• Register
– Mov AL, BL
• Direct
– Mov AL, [20H]
• Register Indirect
– Mov AL, [SI]
Instruction Addressing Modes
1/2002 JNM 16
Segment Register Defaults
1/2002 JNM 17
Standard Assembler Directives
Directive Description
title Title of the listing file
.model Specify the program's memory model
.stack Set the size of the stack segment
.data Mark the beginning of the data segment
.code Mark the beginning of the code segment
proc Begin procedure
endp End of procedure
end End of program assembly
1/2002 JNM 18
Data Allocation DirectivesMnemonic Description Bytes
DB Define byte 1DW Define word 2DD Define Doubleword 4
DF,DP Define far pointer 6DQ Define quadword 8DT Define tenbytes 10
Char1 db ‘A’ hex db 41hSigned1 db -128 dec db 65Signed2 db +127 bin db 01000001bUnsigned db 255 hex2 db 0A3h
1/2002 JNM 19
Lists and Strings
List1 db 10, ‘A’, 41h, 0Ah, 00100010b, 101qListptr db List1
Cstring db “This is a string”,0Clength = ($ - Cstring) ; sets Clength to length of Cstring
db 20 dup(0) ; 20 bytes, all equal to zero db 4 dup(“ABC”) ; 12 bytes, “ABCABCABCABC”
1/2002 JNM 20
Ptr OperatorPtr Operator - For some instructions, the size of the operand is not clear (INC [20H]).
0023 12
0022 34
0021 56
0020 00
0023 12
0022 34
0021 57
0020 00
0023 12
0022 34
0021 56
0020 FF
INC Byte Ptr [0020] INC Word Ptr [0020]
1/2002 JNM 21
0006 560005 780004 120003 340002 790001 630000 35
memory (data)
Direct Addressing Direct-Offset Addressing
Offset operator – returns the 16-bit address of the variable. Good for strings and arrays.
.dataBytelist db 35h, 63h , 79hWordlist dw 1234h, 5678h.code…Mov al, Bytelist ; al = 35Mov al, Bytelist+1 ; al = 63Mov bx, Wordlist ; bx = 1234Mov bx, Wordlist+2 ; bx = 5678
1/2002 JNM 22
0006 470005 4E0004 490003 520002 540001 530000 41
memory (data)
Direct-Offset Addressing with Strings
.dataaString db “ASTRING”
.code…Mov al, aString ; al = 41Mov al, aString+1 ; al = 53Mov al, aString+2 ; al = 54Mov al, aString+3 ; al = 52
1/2002 JNM 23
Bit Name0 CF Carry1 12 PF Parity3 04 AF Auxiliary Carry5 06 ZF Zero7 SF Sign8 TF Trap9 IF Interrupt Enable
10 DF Direction11 OF Overflow12 131415
8086 Flags - Bit Positions and Names
1/2002 JNM 24
Debug Flag Mnemonics F=0
F=1
NV UP DI PL NZ NA PE NCOV DN EI NG ZR AC PO CY
Overflow Direction InterruptEnable
CarryCarry(Negative)
Sign Zero Auxiliary Parity
1/2002 JNM 25
Interrupt Functions(Listed in Appendix G of Irvine Book)
INT 10h – (Video Bios)INT 16h – (Keyboard)INT 33h – (Mouse)
INT 20 – terminate COM program (use INT 21,4C instead)INT 21h – DOS Functions (AH holds function number)
1 – Keyboard input (char; store in AL )2 – Display char (DL holds char)3 – print char (DL holds char)9 – print string (DX points to string) 4Ch – terminate process