110 likes | 270 Views
COSC 456 Lesson 8. Cool Codes. ADD AL,SI AL AL + SI ADD AL,[SI] AL AL + [SI] INC BX BX BX + 1 INC [BX] Ambiguity error INC BYTE PTR [BX] [BX] [BX] + 1 INC WORD PTR [BX]
E N D
Cool Codes • ADD AL,SI AL AL + SI • ADD AL,[SI] AL AL + [SI] • INC BX BX BX + 1 • INC [BX] Ambiguity error • INC BYTE PTR [BX] [BX] [BX] + 1 • INC WORD PTR [BX] [BX + 1 : BX ] [BX + 1 : BX ] + 1
MUL & DIV • MUL CL CL x AL AX • MUL BX BX x AX DX : AX • DIV CL AX/CL calculated. Quotient in AL and remainder in AH • DIV CX DX:AX/CX calculated. Quotient in AX and remainder in DX
Shift SHR Shift Logical Right 0 MSB LSB CF SAL Shift Arithmetic Left 0 MSB LSB CF • Shift CL times! • SHR BX,CL • SAL BX,1 • SAL AL,CL
XCHG & XLAT • XCHG AX, BX • XCHG BL, [SI + 2] • XLAT Translate. Inherent instruction does not require operand specification. This instruction uses AL and BX in the following way: AL [BX + AL ] This instruction finds applications in data translation tables, look-up tables, and code conversions.
Adder Program MOV CX, 7 MOV SI , 0050 MOV AL,0 AGAIN: ADD AL, [SI] INC SI DEC CX JNE AGAIN INT 3 This program adds 7 numbers stored at the memory locations 0050 through 0056.
Adder Program with LOOP MOV CX, 7 MOV SI , 0050 MOV AL,0 AGAIN: ADD AL, [SI] INC SI LOOP AGAIN INT 3 This program adds 7 numbers stored at the memory locations 0050 through 0056. LOOP automatically uses CX as a counter!
String Along! CLD MOV SI, 0200 MOV DI, 0500 MOV CX, 30 REP MOVSB Program copies 30 (48 decimal) bytes of data beginning at0020 to the destination beginning at 0050
SCAN CLD MOV CX,0100H MOV DI, 0200H BACK: MOV AL,0AAH REPNE SCASB JZ JUSTDOIT INT3 JUSTDOIT: MOV AL, 0BBH DEC DI STOSB JMP BACK Program scans memory and replaces AA with BB
CALL & RET HERE :CALL DELAY MOV AL, E3 MOV SI, 0050 CMP AL, [SI] JB HERE INT 3 . . . DELAY:MOV CX,0FFFFH LOOP AGAIN RET Monitors boiler temperature … remember?
Stack … Push and Pop PUSH Saves word (not byte) on stack. First SP is decremented by 2 and then the operand is saved on the stack. POP Increments SP by 2 and then pulls (pops) the word. Example follows: PUSH CX PUSH BX POP CX POP BX The above program is equivalent to XCHG BX,CX