memory address segment-offset address base location (segment) + logical location (offset) example:...
TRANSCRIPT
![Page 1: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/1.jpg)
Memory Address
• Segment-offset address• Base location (segment) + logical location (offset)• Example:• For 32-bits segment-offset address, 08F1:0100
represents a 20-bits absolute address 09010• 0 8 F 1 (0)• 0000 1000 1111 0001 0000• + 0 1 0 0• 0 9 0 1 0•
![Page 2: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/2.jpg)
Floating-Point Unit• 80-bit Registers
ST(0)
ST(1)
ST(7)
FPU Instruction Pointer
FPU Data Pointer
Tag Register
Control Register
Status Register
48-bit Pointer Register
16-bit Control Register
Opcode Register
![Page 3: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/3.jpg)
![Page 4: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/4.jpg)
![Page 5: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/5.jpg)
DUP Operator
• db 20 dup(0) ; 20 bytes, all equal to zero
• db 20 dup (?) ; 20 un-initialized bytes
• db 4 dup(“ABC”) ; 12 bytes: “ABCABCABCABC”
• db 4096 dup(0);
![Page 6: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/6.jpg)
Assembly Language
• Basic elements
• 1. Constant and expression
• 3
• 3.5
• - 3.5
• 26. E+07
![Page 7: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/7.jpg)
Integer Constants
• 26 decimal
• 1Ah hexadecimal
• 1101b binary
• 36q octal
• 2BH hexadecimal
• 43Q octal
• 36D decimal
• 48d decimal
![Page 8: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/8.jpg)
Constant Expression, Symbolic constants and Character or String Constants
• Constant expression
• 5 26.5 4*20 -3*4/6 -2.301E+04
• A symbolic constant
• rows = 5 columns = 10
• Number = rows * columns
• Character or string constant
• ‘ABC’ ‘X’ “ This is a test” “The dog is black”
![Page 9: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/9.jpg)
Assembly Language Statement
• Consists of :
• 1. A name, an instruction mnemonic, operands, and a comment. It has the following form:
• [name] [mnemonic] [operands] [;comment]
• Example:
• call sub1 ; transfer of control
![Page 10: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/10.jpg)
Names• A name identifies a label, variable, symbolic, or
a keyword.• What can be used as a name:• 1. A… Z a… z• 2. 0-9• 3. ?• 4. _ Underscore• 5. @• 6. $• Length limit----maximum of 247 characters (in
MASM)
![Page 11: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/11.jpg)
Variables and Labels
• 1. A variable is a location in a program’s data area that has been assigned a name.
• Such as: count1 db 50 ; • message db “ Hello world!”, odh, 0ah• 2. Label. If a name appears in the code area of a
program, it is called a label.• Example: • LabelA: mov ax, 0• mov bx, ffh•
![Page 12: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/12.jpg)
Hello World Program• title Hello World Program (hello.asm)• ; This program displays "Hello, world!"• .model small• .stack 100h• .data• message db "Hello, world!",0dh,0ah,'$'• .code• main proc• mov ax,@data• mov ds,ax• mov ah,9• mov dx,offset message• int 21h• mov ax,4C00h• int 21h• main endp• end main
![Page 13: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/13.jpg)
Analyze the Program• .model small ----specify the program’s memory model• For that model we can have:• Tiny--- code + data less than 64k• Samll--- code <=64k, data ,<=64k One code segment and
one data segment• Medium---Data <=64k, code any size. Multiple code
segment, one data segment• Compact---Code <= 64k, data any size. Multiple data
segment, one code segment• Large---Code >64k, data >64k both multiple segment• Huge---Same as the large model, except that individual
variables such as arrays may be large than 64k• Flat--- No segments. 32-bits addresses are used for both
code and data. ***Protected mode only
•
![Page 14: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/14.jpg)
Standard Assembler Directives• end---end of program assembly• endp--- end of procedure• page---Set a page format for the listing file• proc---Begin procedure• title---Title of the listing file• .code--- Mark the beginning of the code
segment• .data---• .model---• .stack---Set the size of the stack segment
![Page 15: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/15.jpg)
Data Allocation Directives
• DB--------------------1 byte
• DW-------------------2
• DD--------------------4
• DF, DP---------------6---define far pointer
• DQ--------------------8 define Quadword
• DT--------------------10 define 10 bytes
![Page 16: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/16.jpg)
Examples• Char1 db ‘A’ ; ASCII char.
• Char2 db “A’ –10 ; expression
• Smallest db –128
• Max_unsign db 255
• Myval db ? Only reserve memory, no initializeers
• List db 10,20,30,40,50
![Page 17: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/17.jpg)
Characters and Integers are one and the same
• Char db ‘A’
• Hex db 41h
• Dec db 65
• Bin db 01000001
• Oct db 101q
![Page 18: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/18.jpg)
Type mix is allowed
• List db 10, 20, 41h, 10011000b
• List2 db 0ah, 29h, ‘a’, 22
![Page 19: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/19.jpg)
Strings
• Cstring db “Good morning”,0
• Pstring db 12, “Good morning”
• Longstring db “This is a long string, that”• db “ clearly is going to take”• db “ several lines to store”,0
![Page 20: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/20.jpg)
Symbolic Constants• Equate directives• They allow constants and literals to be
given symbolic names.
• 1. Equal-Sign Directive (redefinable)• The syntax is: name = expression• Examples: string = ‘XY’• count = 500• minInt = 8000h•
![Page 21: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/21.jpg)
To assign a 32 bits integer---.386 is required
• .386
• maxLong = 7FFFFFFFh ; maximum 32-bit signed value
• minLong = 80000000h ; Minimum 32-bit signed value
• “=“ defined symbols can be redefined any number of times.
![Page 22: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/22.jpg)
Example of Using Directives
• count =5
• mov al , count
• mov dl , al
• count =10
• mov cx , count
• count = 2000
• mov ax, count
![Page 23: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/23.jpg)
EQU and TEXTEQU directives• EQU is not redefinable
• TEXTEQU is redefinable
• Examples: maxint equ 32767; Numeric
• float1 equ <3.1416> ; String
• TEXTEQU syntax:
• name TEXREQU <text>
• name TEXTEQU textmacro
![Page 24: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/24.jpg)
Intel chip Instructions
• 1. MOV---Data transfer instruction
• Instruction format:• MOV reg, reg MOV reg, immed• MOV mem, reg MOV mem, immed• MOV reg, mem
MOV mem16, segreg• MOV reg16, segreg • MOV segreg, immed16• MOV segreg, reg16• *** Flag bits are not affected by MOV instruction
![Page 25: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/25.jpg)
Examples
• .data
• count db 10
• total dw 4126h
• bigVal dd 12345678h
• .code
• mov al, bl
• mov bl, count
• mov count, 26
• mov bl, 1
![Page 26: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/26.jpg)
Examples—cont…• mov dx, cx
• mov bx, 8FE2h
• mov total, 1000h
• mov eax, ebx
• mov edx, bigVal ; 32-bit memory to reg
• ***Pay attention the the fact that operands size must match. Otherwise, the assembler will return an error for any size mismatch.
![Page 27: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/27.jpg)
Example
• .data • count dw 20h ; 20h---here really mean 0020h
• .code• mov al, count; error:
![Page 28: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/28.jpg)
XCHG Instruction
• XCHG reg, reg
• xchg ax, bx
• xchg eax, ebx
• XCHG reg, mem
• xchg ax, value1
• XCHG mem, reg
• xchg value2, cx
![Page 29: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/29.jpg)
Program example• Title Exchange Two Variables (Exchange.asm)• .model small• .stack 100h• .data• Value1 db 0ah• Value2 db 14h• .code• Main proc• Mov ax, @data ; initialize DS register• Mov ds, ax• Mov al, value1• Xchg value2, al• Mov value1, al• Mov ax, 4c00h• Int 21h• Main endp• End main; Question: Why don’t we use xchg value1, value2?
![Page 30: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/30.jpg)
Arithmetic Instructions
• ADD and SUB instructions
• ADD reg, reg
• ADD mem, reg
• ADD reg, mem
• ADD reg, immed
• ADD mem, immed
• ADD accum, immed• Flag O D I S Z A P C
• SUB has the similar instruction format
* * * * * *
![Page 31: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/31.jpg)
Examples• Mov ax, 10
• Sub ax, 10 ; AX=0, ZF =1
• Mov bx, 1
• Sub bx, 2 ; BC = FFFF, SF = 1
• Mov ax, 0FFh
• Add al, 1 ; AL = 00 , CF = 1
![Page 32: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/32.jpg)
Basic Operand Types• There are three basic types of operands:
• 1. Immediate----a constant
• 2. Register-------one of the CPU’s register
• 3. Memory---a reference to a mem.Location
• There are six different types of memory operands:
• Direct, direct-offset, register-indirect
• Indexed, base-indexed, and base-indexed with displacement
![Page 33: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/33.jpg)
Example
• mov ax, [si] --- this is called register-indirect
• Here si register hold the beginning address for a list of numbers.
• The first number in the address will be moved to al and the second number will be moved into ah.
![Page 34: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/34.jpg)
Immediate operands, Direct Operands, and Direct-Offset operands
• 1. Immediate operands:
• Mov al, 10 ; ----a number
• Mov eax, 12345678h ; ---a 4-byte number
• Mov dl, ‘X’ ; --- a character
• Mov ax, (40 *50) ; arithmetic expression
![Page 35: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/35.jpg)
Direct Operands• .data
• Count db 20
• Wordlist dw 1000h, 2000h
• LongVal dd 11223344h
• .code
• Mov al, Count
• Mov bx, Wordlist +2
• Mov edx, LongVal
![Page 36: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/36.jpg)
Direct Offset Operands
• .data
• Array db 0ah, 0bh, 0ch, 0dh
• .code
• Mov al, array ; 0ah-al
• Mov bl, array +1 ; 0bh bl
• Mov cl, array + 2 ; 0ch cl
• Mov dl, array +3 ; 0dh dl
![Page 37: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/37.jpg)
Another Example
![Page 38: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/38.jpg)
IA – 32 Processor Architecture
• IA – 32 processor have three basic mode of operations:
• 1. Protected Mode
• 2. Real-address Mode
• 3. System Management Mode
![Page 39: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/39.jpg)
Protected Mode
• IA-32 processors have three basic modes of operation: Protected mode, Real-address mode and System Management mode. In addition, the Virtual-8086 mode is a special case of Protected mode.
![Page 40: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/40.jpg)
1. Protected Mode
• Protected mode is the native state of the processor, in which all instructions and features are available.
• Programs are given separate memory areas (called segment), and the processor detects any attempt by a program to reference memory outside its assigned segment.
• Each program can address up to 4GB memory.
![Page 41: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/41.jpg)
Virtual – 8086 Mode
• While in Protected mode, the processor can directly execute Real-address mode software such as MS-DOS programs in a safe multitasking environment.
• In other word, even if an MS-DOS program crashes, it will not affect other program running at the same time.
![Page 42: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/42.jpg)
Real-address mode
• It offers us a few more features, such as the ability to switch into other two modes.
• Only 1 MB of memory can be addressed:
• 00000h-FFFFFh
• The processor can only run one program a time.
![Page 43: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/43.jpg)
System Management Mode
• SSM-mode• It provides an operating system with a mechanism
for implementing such functions as power management and system security.
• These functions are usually implemented by computer manufacturers who want to customize the processor for a particular system setup.
![Page 44: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/44.jpg)
Homework6
• Write and run an assembly program under debug that will:• 1) Add numbers from 1 to 1000.• Note: you would need these following instructions:• A) jz – jump if zero• B) mov cx, number of times (1000 in Hex.)• C) create the labels that tells program where to go when
certain conditions are met. • Due: 11/07 Turn in: Your code and the running result.
![Page 45: Memory Address Segment-offset address Base location (segment) + logical location (offset) Example: For 32-bits segment-offset address, 08F1:0100 represents](https://reader033.vdocument.in/reader033/viewer/2022061601/56649cec5503460f949b80e2/html5/thumbnails/45.jpg)
Note to the debug usage
• You can assemble your assembly language program with other software and load the code into the memory by using the debug as follows:
• Under debug: (Click start, click Run, type cmd and type enter)
• N a:hello.exe• L• This will load your code from a: to the memory
address beginning at CS:0100.