國立臺北大學資工系江宥旻
8088/8086 programming - control flow instructions and program structures
Introducion
This chapter will cover following instructions
- Flag-Control instructions
- Compare instructions
- Control Flow and the Jump instructions
- Subroutines and subroutine-handling instructions
- Loop and Loop-Handling instructions
- String and string-Handling instructions
Flag-control instructions
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
LAHF和SAHF在OS很重要
Example
Save flag to MEM1 and reload the flags with the contents of MEM2
OS執行兩個程式(程式A和程式B)
A執行1ms後,要換B時
把A存在memory裡,換B執行
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
SR:Status Register
Compare instrution
CMP
- Determine the relationship between two numbers
- No operands are affected excepts for flags
- Basically a subtraction operation
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Example
Please show that all of flags
AX = 0001001000110100
BX = 1010101111001101
CMP = 0110011001100111 (CMP是把AX減去BX來看AX和BX的大小關係,不會存在任何地方)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Control flow and the JUMP instructions
Jump instrutions
-
Unconditions jump
- Jmp instruction
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Condtion jump
- Jxx instruction (有很多,用xx代替)
- The condition refers to specific status flag
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- When the jump instruction is executed, IP is reload with a new value
- IP+2 plus the signed displacement
- Intrasegment jump(同區段跳躍) v.s. intersegment jump(跳區段跳躍)
-
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Short-label, near-label, Memptr 16 or register 16 operand
-
若無法被64K涵蓋就需要跳區段
-
- Condition jump instruction
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Condition jump
- JC Lable
offset is specified
- JB Lable
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Branch program structure
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
The loop program structure - Repeat-until and While-Do
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Applications
- Block-move program (區塊移動)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
ADDR:address
BLK1到BLK2移動了n
DS * 16 + SI DS * 16 + DI
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
一個一個Byte移動
Subroutines and subroutine-handling instructions
- Subroutine
- Call subroutine
- IP or CS and IP must be modified
- Call instruction
- Ret instruction


- Intrasegment call (in same segment)
- Intersegment call (cross over different segment)
- RET
Example

Push and Pop instruction
- Compiler自己做的
- 防止主程式call到副程式時,更改到Reg的value
- 副程式會用到的Reg,主程式會先存原本的值,避免被更改到

- Push ax
- sp - 1 <- ah
- sp - 2 <- al
- sp <- sp - 2
- Pop ax
- al <- sp
- ah <- sp + 1
- sp <- sp + 2
針對Flag的Push and Pop
- PUSHF
- Push flag register on the top of the stack
- POPF
- Pop flag register from the top of the stack

LOOPS and LOOP-handling instructions

CX:Count Register
LOOP CX != 0
LOOPE/LOOPZ CX != 0 && ZF = 1
LOOPNE/LOOPNE CX != 0 && ZF = 0
Example (比較Block-move prog)

這裡用的是LOOP,所以沒有DEC CX,因為LOOP會自己幫CX減一。
Example

Strings and String-handling instructions
Basic string insruction


- block move program using the move-string instruction

一二行就是得這樣寫
- block scan operation using the SCASB instruction

字元比對:在一個區塊找有沒有AL的值
- Initialing a block of memory with a store string operation

String的每一個Byte都設為05
REP STOSB
- AGAIN STOSB
- LOOP AGAIN
程式可以去參考emu86的sample code
參考資料
- Barry B. Bery, “The Intel Microprocessors,” 8th Edition, 2009, Prentice Hall.
- Walter A. Triebel, Avtar Singh, “The 8088 and 8086 Microprocessors – Programming, Interfacing, Software, Hardware, and Applications,” 4th Edition, 2003, Prentice Hall.
- 國立臺北大學資工系張玉山教授ppt