Introduction To Microprocessors Review
Introduction To Microprocessors Review
Topics
Simplified segment definition
Directives
Directives
PAGE and TITLE
PAGE [lines], [column] tell the printer how the list should be printed. Default setting PAGE (no numbers after it): 66 lines per page and max. 80 and characters PAGE 60,132 the range of number of lines = 10 t0 255 and range of columns = 60 to 132. TITLE put the name of the program and a brief description of the function of function the program.
.STACK ; marks the beginning of the stack segment .DATA ; marks the beginning of the data segment .CODE; marks the beginning of the code segment .STACK 64 ; reserves 64 bytes of memory for the stack
FAR: control transfer outside the current code segment intersegment (between segment)
- A FAR jump
5
mov ax,@data ; data refers to the start of the data segment mov ds,ax
2102440 Introduction to Microprocessors
Short Jumps
All conditional jumps are short jumps. The address of the target must be within -128 to +127 bytes of the IP (256 possible addresses). - for the backward jump and + for the forward jump.
Unconditional jump
JMP label label To transfer unconditionally to the target location label.
SHORT JUMP JMP SHORT label (-128 to label 127 bytes) NEAR JUMP JMP label (within the current label code segment); the target address can be any of the addressing modes of direct, register, or register indirect. FAR JUMP JMP FAR PTR label (CS and IP label are replaced with new values)
2102440 Introduction to Microprocessors
10
CALL statements
CALL instruction is used to call a procedure. NEAR call within the current code segment. Only IP is saved on the stack. FAR call > outside the current code segment. Both CS and IP are saved on the stack.
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------MAIN PROC FAR ; This is the entry point for DOS MOV AX,@DATA MOV DS, AX CALL SUBR1 CALL SUBR2 MOV AH,4cH INT 21H MAIN ENDP ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SUBR1 PROC ... ... RET SUBR1 ENDP ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SUBR2 PROC ... ... RET SUBR2 ENDP ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------END MAIN ; This is the exit point
The destination operand can be a register or in memory. The source operand can be a register, in memory, or immediate. Memory-to-memory operations are not ALLOWED in Memory- to80x86.
11
12
2.
3. 4.
Run the Linker to generate an .EXE file from the .OBJ file
tlink yourfile
5.
13
14
Sample Program 1
;This program calculates the total sum of 5 bytes of data. Each byte represents the daily wages ; of a worker. This person does not make more than $255 (FFH) a day TITLE PROG3-1A (EXE) ADDING 5 BYTES PROG3PAGE 60,132 .MODEL SMALL .STACK 64 ;-------------.DATA COUNT EQU 05 DATA DB 125,235,197,91,48 ORG 0008H SUM DW ? ;-------------2102440 Introduction to Microprocessors
BACK: OVER:
;CX is the loop counter ;SI is the data pointer ;AX will hold the sum ;add the next byte to AL ;If no carry, continue ;else accumulate carry in AH ;increment data pointer ;decrement loop counter ;if not finished, go add next byte ;store sum ;go back to DOS
MAIN
15
Sample Program 2
;This program calculates the total sum of five words of data. Each data Each value represents the yearly ; wages of a worker. This person does not make more than $65,555 $65,555 (FFFFH) a year TITLE PROG3-1B (EXE) ADDING 5 WORDS PROG3PAGE 60,132 .MODEL SMALL .STACK 64 ;-------------.DATA COUNT EQU 05 DATA DW 27345,28521,29533,30105,32375 ORG 0010H SUM DW 2 DUP(?) ;-------------2102440 Introduction to Microprocessors
17
18
BACK:
MAIN
19