1 / 44

Memory Address

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

livia
Download Presentation

Memory Address

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Floating-Point Unit 80-bit Registers 48-bit Pointer Register ST(0) FPU Instruction Pointer ST(1) FPU Data Pointer Tag Register Control Register Status Register 16-bit Control Register ST(7) Opcode Register

  3. 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);

  4. Assembly Language • Basic elements • 1. Constant and expression • 3 • 3.5 • - 3.5 • 26. E+07

  5. Integer Constants • 26 decimal • 1Ah hexadecimal • 1101b binary • 36q octal • 2BH hexadecimal • 43Q octal • 36D decimal • 48d decimal

  6. 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”

  7. 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

  8. 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)

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. Characters and Integers are one and the same • Char db ‘A’ • Hex db 41h • Dec db 65 • Bin db 01000001 • Oct db 101q

  16. Type mix is allowed • List db 10, 20, 41h, 10011000b • List2 db 0ah, 29h, ‘a’, 22

  17. 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

  18. 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

  19. 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.

  20. Example of Using Directives • count =5 • mov al , count • mov dl , al • count =10 • mov cx , count • count = 2000 • mov ax, count

  21. 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

  22. 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

  23. Examples • .data • count db 10 • total dw 4126h • bigVal dd 12345678h • .code • mov al, bl • mov bl, count • mov count, 26 • mov bl, 1

  24. 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.

  25. Example • .data • count dw 20h ; 20h---here really mean 0020h • .code • mov al, count; error:

  26. XCHG Instruction • XCHG reg, reg • xchg ax, bx • xchg eax, ebx • XCHG reg, mem • xchg ax, value1 • XCHG mem, reg • xchg value2, cx

  27. 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?

  28. 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 * * * * * *

  29. 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

  30. 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

  31. 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.

  32. 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

  33. Direct Operands • .data • Count db 20 • Wordlist dw 1000h, 2000h • LongVal dd 11223344h • .code • Mov al, Count • Mov bx, Wordlist +2 • Mov edx, LongVal

  34. 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

  35. Another Example

  36. IA – 32 Processor Architecture • IA – 32 processor have three basic mode of operations: • 1. Protected Mode • 2. Real-address Mode • 3. System Management Mode

  37. 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.

  38. 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.

  39. 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 is an MS-DOS program crashes, it will not affect other program running at the same time.

  40. 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.

  41. 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.

  42. Homework11 • 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 where to go.

More Related