Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data.

Similar presentations


Presentation on theme: "Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data."— Presentation transcript:

1 Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data in > 1 segment LARGECode in > one segment Data in > 1 segment Array is not more than 64KB HUGECode in > 1 segment Data in > one segment Aray is larger than 64KB

2 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

3 Stack Segment Is used to reserve one memory block to store stack Definition syntax.STACKsize(size is optional) E.g:.STACK100H The above statement will prepare 100h byte for stack area

4 Code Segment Contain program instructions Syntax declaration.CODEname;where name is ;the chosen of ;the segment Instruction is in procedure form

5 Simple procedure declaration: namePROC ; procedure body nameENDP where name (procedure name); PROC and ENDP (pseudo-op which describe procedure)

6 Eg:.CODE MAIN PROC ;main procedure instruction MAIN ENDP ;other procedure starts here

7 Combination of segments One general form programming model using memory model..SMALL can be constructed.MODELSMALL STACK100H.DATA ;data declaration starts here.CODE MAINPROC ;instruction starts here MAINENDP ;other procedures starts here ENDMAIN Last line must be END, followed by main procedure name

8 8086 Instruction Set

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

10 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

11 MOV (MOVe) Transfer from source operand to destination operand Format MOV OD, OS;where OS= source ;operand ;OD=destination ;operand Execution example Source OperandDestination Operand Before operationXXXYYY After operationXXX

12 Destination operand Source operandExample General register MOV AX, BX Segment registerGeneral registerMOV DS, AX MemoryRegisterMOV [BX],AX General registerMemoryMOV AX,BETA RegisterConstant /immediate value MOV AX,5H MemoryConstant /immediate value MOV [BX],45H General registerSegment registerMOV AX,DS Segment registerMemoryMOV DS,[BX] MemoryConstant /immediate value MOV [BX],25H Valid source and destination operand

13 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

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

15 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 AXDX BeforeXXXYYY AfterYYYXXX

16 Can involve 8 and 16 bit data but size must be equivalent For instruction involve memory space like XCHG [SUM],BX exchange is as XCHG [SUM],BX  ((DS)OH+SUM)  BX

17 Exchange 2 variable 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 ; 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 21h main endp end main

18 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

19 ADD (ADDition) Perform addition between source operand and destination operand and result is stored in operand destination Format ADD OD,OS ;where OD=destination ;operand ;OS=source operand ADD OD,OS OD+OS  OD (if there is a carry, carry flag, CF=1)

20 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

21 ADD Instruction Examples.data membyte db 25 memword dw 36 doubleVal dd 12340000h.code add al,5 add bx,ax add eax,edx add membyte,al add memword,bx add doubleVal,edx

22 Valid destination operand and source operand combination Destination operand Source operandInstruction example General register ADD AX,DX MemoryGeneral registerADD [BX],AX General registerMemoryADD AX,[BX] Immediate valueGeneral registerADD AX,35 Immediate valueMemoryADD BYTE PTR [BX],5H

23 Instruction example If AX=1234H, BX=0001H, therefore ADD AX,BX is as in the table below AXBXCarry Flag 1Before1234H0001Hx After1235H0001H0 2Before1234HEF00Hx After0134HEF00H1

24 SUB Instruction Format : 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

25 SUB Instruction Example.data membyte db 25 memword dw 36 doubleVal dd 12340000h.code sub al,5 sub bx,ax sub eax,edx sub membyte,al sub memword,bx sub doubleVal,edx


Download ppt "Memory model ModelDescription SMALLCode in one segment Data in one segment MEDIUMCode in > 1 segment Data in one segment COMPACTCode in one segment Data."

Similar presentations


Ads by Google