DAT2343 Implementing Standard Logic Flows with 80x86 Assembler © Alan T. Pinck / Algonquin College; 2003
Jumping Out of Sequence Basic Form JMP address “address” will normally be specified using a label reference (but could be specified as a literal numeric address)
Variance In Numeric Code for a JMP Samples of numeric code for various JMP instructions (from DEBUG) 0ADB:021A EB04 JMP ADB:021C EBF2 JMP ADB:021E E9FF00 JMP ADB:0221 E9FCFE JMP ADB:0224 EA B JMP 0B48:0320 Short: address within -127 to +128 of IP value (1 byte address) Near: address within the same segment (2 byte address) Far: address within a different segment (4 byte address)
Basic 80x86 Flags & Conditional Jump Mnemonics Zero flag (NZ, ZR) JNZ …; JZ … Carry flag (NC, CY) JNC …; JC … Sign flag (PL, NG) JNS …; JS … Overflow flag (NV, OV) JNO …; JO …
Basic 80x86 Flags & Conditional Jump Mnemonics (2) Important Note: All conditional jumps are “short” There are 4 other flags (which we will not use in this course): Parity, Interrupt Enable, Direction, and Auxiliary Carry There are some additional conditional jump mnemonics (presented on later slides) which combine flag settings.
Instructions Which Modify The Flags Most arithmetic operations: ADD, SUB, INC, DEC, CMP Bit-level logical operations: AND, OR, XOR, NOT Shifts and Rotates SHL, SHR, ROL, ROR
Instructions Which Do NOT Modify The Flags Any instruction not identified on the previous slide; Specifically, the following do NOT modify the flags: MOV IN JMP/Jxx
Unsigned Comparisons Less than (before)JB Less than Or Equal toJBE Equal toJE (or JZ) Not Equal toJNE (or JNZ) Greater than (after) Or EqualJAE Greater thanJA
Signed Comparisons Less thanJL Less than Or Equal toJLE Equal toJE (or JZ) Not Equal toJNE (or JNZ) Greater than Or Equal toJGE Greater thanJG
Limitations on Conditional Jump Distance As noted earlier all conditional jumps must be short jumps; the address must be within +127 and -128 bytes of the instruction following the conditional jump. When the location is further away than this a reversed conditional jump over a near (or far) jump must be used: JNC SkipCarryError JMP CarryError ;more than 128 bytes away SkipCarryError:
Implementing the IF…ELSE Structure IF num1 < num2 THEN ….. ELSE …. ENDIF mov ax,num1 sub ax,num2 jc then jmp else then: …… jmp endif else: …… endif:
Implementing the WHILE Structure WHILE num1 < num2 DO ….. ENDWHILE while: mov ax,num1 sub ax,num2 jc do jmp endw do: ……. jmp while endw:
Calling a Near Sub-Procedure To call a procedure within the same segment as the call: CALL procName
Near Procedure Structure Must be coded within the same segment as any call to this procedure: procName PROC NEAR ; instructions required by procedure RET procNameENDP
Calling a Far Sub-Procedure To call a procedure “procName” within a segment called “segName”: CALL segName:procName
Far Procedure Structure segName SEGMENT ; … procName PROC FAR ; instructions required for proc RET ; (translated as RETF, ; return far) procName ENDP ; … segName ENDS
End of Lecture