cosc 456 lesson 8 cool codes add al,sial al + si add al,[si]al al + [si] inc bxbx bx + 1 inc...

Post on 30-Dec-2015

216 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

COSC 456Lesson 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][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

SHRShift Logical Right

0 MSB LSB CF

SALShift 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, 7MOV SI , 0050

MOV AL,0AGAIN: ADD AL, [SI]

INC SIDEC CX

JNE AGAININT 3

This program adds 7 numbers stored at the memory locations 0050 through 0056.

Adder Program with LOOP

MOV CX, 7MOV SI , 0050

MOV AL,0AGAIN: ADD AL, [SI]

INC SILOOP 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

CLDMOV CX,0100HMOV DI, 0200H

BACK: MOV AL,0AAHREPNE SCASBJZ JUSTDOITINT3

JUSTDOIT: MOV AL, 0BBHDEC DISTOSBJMP BACK

Program scans memory and replaces AA with BB

CALL & RET

HERE :CALL DELAYMOV AL, E3

MOV SI, 0050CMP AL, [SI]

JB HEREINT 3. . .

DELAY:MOV CX,0FFFFHLOOP 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 CXPUSH BXPOP CXPOP BX

The above program is equivalent to XCHG BX,CX

top related