+ All Categories
Home > Documents > Memory model

Memory model

Date post: 20-Mar-2016
Category:
Upload: mahola
View: 45 times
Download: 0 times
Share this document with a friend
Description:
Memory model. Data Segment. Contain all variable declaration To declare data segment, directive .DATA, followed by variable or constant declaration E.g. .DATA WORD1DW2 WORD2DW5 MSGDB ‘INI ADALAH MESEJ’ MASKEQU 10010010B. Stack Segment. - PowerPoint PPT Presentation
25
Memory model Model Description SMALL Code in one segment Data in one segment MEDIUM Code in > 1 segment Data in one segment COMPACT Code in one segment Data in > 1 segment LARGE Code in > one segment Data in > 1 segment Array is not more than 64KB HUGE Code in > 1 segment Data in > one segment Aray is larger than 64KB
Transcript
Page 1: Memory model

Memory modelModel DescriptionSMALL Code in one segment

Data in one segmentMEDIUM Code in > 1 segment

Data in one segmentCOMPACT Code in one segment

Data in > 1 segmentLARGE Code in > one segment

Data in > 1 segmentArray is not more than 64KB

HUGE Code in > 1 segmentData in > one segmentAray is larger than 64KB

Page 2: Memory model

Data Segment Contain all variable declaration To declare data segment,

directive .DATA, followed by variable or constant declaration

E.g.– .DATA– WORD1 DW 2– WORD2 DW 5– MSG DB ‘INI ADALAH MESEJ’– MASK EQU 10010010B

Page 3: Memory model

Stack Segment

Is used to reserve one memory block to store stack

Definition syntax.STACK size (size is optional)E.g: .STACK 100H

The above statement will prepare 100h byte for stack area

Page 4: Memory model

Code Segment

Contain program instructions Syntax declaration

.CODE name ;where name is ;the chosen of ;the segment

Instruction is in procedure form

Page 5: Memory model

Simple procedure declaration:name PROC; procedure bodyname ENDPwhere name (procedure name); PROC and ENDP (pseudo-op which describe procedure)

Page 6: Memory model

Eg:.CODEMAIN PROC;main procedure instructionMAIN ENDP;other procedure starts here

Page 7: Memory model

Combination of segments One general form programming model using memory

model. .SMALL can be constructed.MODEL SMALLSTACK 100H.DATA;data declaration starts here.CODEMAIN PROC;instruction starts hereMAIN ENDP;other procedures starts hereEND MAIN

Last line must be END, followed by main procedure name

Page 8: Memory model

8086 Instruction Set

Page 9: Memory model

Instruction Types Data transfer instruction Arithmetic instruction Bit control instruction Compare instruction Jump/branch instruction Loop instruction

Page 10: Memory model

Data Transfer Instruction Used to transfer data

– Between one internal register with other internal register

– Between internal register with one storage location in memory

– Between one internal register with immediate value

Instructions such as MOV and XCHG

Page 11: Memory model

MOV (MOVe) Transfer from source operand to destination

operand Format

MOV OD, OS ;where OS= source ;operand

;OD=destination ;operand

Execution example

Source Operand Destination Operand

Before operation XXX YYY

After operation XXX XXX

Page 12: Memory model

Destination operand

Source operand Example

General register General register MOV AX, BX

Segment register General register MOV DS, AX

Memory Register MOV [BX],AX

General register Memory MOV AX,BETA

Register Constant /immediate value

MOV AX,5H

Memory Constant /immediate value

MOV [BX],45H

General register Segment register MOV AX,DS

Segment register Memory MOV DS,[BX]

Memory Constant /immediate value

MOV [BX],25H

Valid source and destination operand

Page 13: Memory model

To transfer both source and destination operand which is the memory space can be done with instruction

MOV AX,BETA ;copy BETA content into AX

MOV ALPHA,AX ;copy AX content into ;ALPHA

Transger must be between equivalent data size, example:

MOV AL,1234H ;is not allowed because ;insert data with

16-bit size ;into 8-bit size register

Page 14: Memory model

Example copy MOV instruction with register addressing mode and direct addressing mode– Register addressing mode

MOV AX,BX (BX) (AX)– Direct addressing mode

MOV CX,[ABCD] ((DS)OH+ABCD) (CL)

((DS)OH+ABCD+1)(CH)

Page 15: Memory model

XCHG (EXCHange) Exchangfe between source operand with

destination operand Format

XCHG OD,OS ;where OD=destination ;operand ;OS=source

operand Instruction execution XCHG AX,DX

AX DX

Before XXX YYY

After YYY XXX

Page 16: Memory model

Can involve 8 and 16 bit data but size must be equivalent

For instruction involve memory space like XCHG [SUM],BX

exchange is asXCHG [SUM],BX ((DS)OH+SUM)BX

Page 17: Memory model

Exchange 2 variabletitle Exchange Two Variables     (Exchange.asm).model small.stack 100h.datavalue1 db 0Ahvalue2 db 14h.codemain proc    mov  ax,@data      ; initialize DS register    mov  ds,ax    mov  al,value1     ; load the AL register    xchg value2,al     ; exchange AL and value2    mov  value1,al     ; store AL back into value1

    mov  ax,4C00h      ; exit program    int  21hmain endpend main

Page 18: Memory model

Arithmetic Instruction Involve additional instruction (ADD),

subtraction (SUB), multiplication (MUL) and division (DIV)

Also contain this instruction variation For instruction such as ADC instruction

including carry flag instruction

Page 19: Memory model

ADD (ADDition) Perform addition between source operand

and destination operand and result is stored in operand destination

FormatADD OD,OS ;where OD=destination

;operand ;OS=source operand

ADD OD,OSOD+OS OD

(if there is a carry, carry flag,

CF=1)

Page 20: Memory model

ADD instruction

Source operand can be register, immediate value or memory

Destination operand can be register or memory

Only one operand can be memory operand

Page 21: Memory model

ADD Instruction Examples

.datamembyte db 25memword dw 36doubleVal dd 12340000h.codeadd al,5add bx,axadd eax,edxadd membyte,aladd memword,bxadd doubleVal,edx

Page 22: Memory model

Valid destination operand and source operand combination

Destination operand

Source operand Instruction example

General register General register ADD AX,DX

Memory General register ADD [BX],AX

General register Memory ADD AX,[BX]

Immediate value General register ADD AX,35

Immediate value Memory ADD BYTE PTR [BX],5H

Page 23: Memory model

Instruction example If AX=1234H, BX=0001H, therefore

ADD AX,BX is as in the table below

AX BX Carry Flag1 Before 1234H 0001H x

After 1235H 0001H 0

2 Before 1234H EF00H x

After 0134H EF00H 1

Page 24: Memory model

SUB InstructionFormat : SUB OD, OS ;where OS source operand ;OD destination operand Subtract source operand from destination operand Source operand can be register, immediate value

or memory Destination operand can be register or memory Only one operand can be memory operand

Page 25: Memory model

SUB Instruction Example

.datamembyte db 25memword dw 36doubleVal dd 12340000h.codesub al,5sub bx,axsub eax,edxsub membyte,alsub memword,bxsub doubleVal,edx


Recommended