ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» º Adam's Assembler Tutorial 1.0 ÇÄ¿ º º ³ º PART V º ³ ÈÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Revision : 1.5 Date : 15-03-1996 Contact : blackcat@faroc.com.au http://www.faroc.com.au/~blackcat Note : Adam's Assembler Tutorial is COPYRIGHT, and all rights are reserved by the author. You may freely redistribute only the ORIGINAL archive, and the tutorials should not be edited in any form. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Well, another week or so seems to have gone by... Another week I should have been using to accomplish something useful. Anyway, it seems that the tutorials have gained a bit more popularity, which is good. I've also received some demo code from someone who seems to have found the tutorials of some use. Please, if you attempt something either with the help of the tutorials or on your own, please send it to me. I like to see what people have made of my work, or just how creative you all are. If you write something that I think could be useful for others to learn from, or is just pretty cool, I'll stick it up on my web site. Note that I included a starfield demonstration in this week's tutorial just for the hell of it. You can run STARS.EXE, or look at STARS.PAS for the full source. It's only a simple demo, but it can be used to achieve some very nice effects. Now, this week we're firstly going to list a summary of all the instructions that you should have learnt by now, and a few new ones as well. Then we'll take a look at how the VGA is arranged, and cover a simple line routine. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³ THE INSTRUCTION SET SUMMARY ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ þ ADC , - Name: Add with Carry Type: 8086+ Description: This instruction adds to and adds the value stored in the carry flag, which will be a one or a zero to also. Basically, DEST = DEST + SOURCE + CF EG: ADC AX, BX þ ADD , - Name: Add Type: 8086+ Description: This instruction adds and , storing the result in . EG: ADD AX, BX þ AND , - Name: Boolean AND Type: 8086+ Description: This instruction performs a bit by bit comparison of and , storing the result in . EG: AND 0, 0 = 0 AND 0, 1 = 0 AND 1, 0 = 0 AND 1, 1 = 1 þ BT , - Name: Bit Test Type: 80386+ Description: This instruction tests of which can either be a 16 or 32-bit register or memory location. If is a 16-bit number then can range from 0 - 15, else if is a 32-bit number, then may have a value from 0 to 31. The value held in of is then copied into the carry flag. EG: BT AX, 3 JC WasEqualToOne þ CALL - Name: Procedure Call Type: 8086+ Description: This instruction simply calls a subroutine. In more technical terms, it pushes the address of the next instruction, IP, onto the stack, and then sets the instruction pointer, IP, to the value specified by . EG: CALL MyProc þ CBW - Name: Convert Byte to Word Type: 8086+ Description: This instruction extends the byte in AL to AX. EG: MOV AL, 01h CBW ADD BX, AX ; Do something with AX þ CLC - Name: Clear Carry Flag Type: 8086+ Description: This instruction clears the carry flag in the flags register to 0. EG: CLC þ CLD - Name: Clear Direction Flag Type: 8086+ Description: This instruction clears the direction flag in the flags register to 0. When the direction flag is 0, any string instructions increment the index registers SI and DI. EG: CLD þ CLI - Name: Clear Interrupt Flag Type: 8086+ Description: This instruction clears the interrupt flag in the flags register to 0, thus disabling hardware interrupts. EG: CLI þ CMC - Name: Complement the Carry Flag Type: 8086+ Description: This instruction checks the value currently held in the carry flag. If it is 0 - it becomes a 1 and if it is 1 - it becomes a 0. EG: BT AX, 1 ; Test bit 1 of AX JC WasOne JMP Done WasOne: CMC ; Return CF to 0 Done: þ CMP , - Name: Compare Integer Type: 8086+ Description: This instruction compares and and reflects the comparison in the flags. EG: CMP AX, BX See also the Jcc instructions. þ CWD - Name: Convert Word to Doubleword Type: 8086+ Description: This instruction extends the word in AX to the DX:AX pair. EG: CWD þ DEC - Name: Decrement Type: 8086+ Description: This instruction subtracts one from the value held in and stores the result in . EG: DEC AX þ DIV - Name: Unsigned Division Type: 8086+ Description: This instruction divides by either AX for a byte, DX:AX for a word or EDX:EAX for a doubleword. For a byte, the quotient is returned in AL and the remainder in AH, for a word the quotient is returned in AX and the remainder in DX and for a DWORD, the quotient is returned in EAX and the remainder in EDX. EG: MOV AX, 12 MOV BH, 5 DIV BH MOV Quotient, AL MOV Remainder, AH þ IN , - Name: Input from I/O port Type: 8086+ Description: This instruction reads a value from one of the 65536 hardware ports into the specified accumulator. AX and AL are commonly used for input ports, and DX is commonly used to identify the port. EG: IN AX, 72h MOV DX, 3C7h IN AL, DX þ INC - Name: Increment Type: 8086+ Description: This instruction adds one to the number held in , and stores the result in . EG: MOV AX, 13h ; AX = 13h INC AX ; AX = 14h þ INT - Name: Generate an Interrupt Type: 8086+ Description: This instruction saves the current flags and instruction pointer on the stack, and then calls based on the value in AH. EG: MOV AH, 00h ; Set video mode MOV AL, 13h ; Video mode 13h INT 10h ; Generate interrupt þ Jcc - Name: Jump if Condition Type: 8086+ I'm not going to repeat myself for all 32 of them, just look in Tutorial Three for the entire list of them. Bear in mind that it would be a good idea to call CMP, OR, DEC or something similar before you use one of these instructions. :) EG: DEC AX JZ AX_Has_Reached_Zero þ JMP - Name: Jump Type: 8086+ Description: This instruction simply loads a new value, , into the instruction pointer, thus transferring control to another part of the code. EG: JMP MyLabel þ LAHF - Name: Load AH with Flags Type: 8086+ Description: This instruction copies the low bytes of the flags register into AH. The contents of AH will look something like the following after the instruction has been executed: ÚÄÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿ ³ Flag ³ SF ³ ZF ³ -- ³ AF ³ -- ³ PF ³ -- ³ CF ³ ÃÄÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´ ³ Bit ³ 07 ³ 06 ³ 05 ³ 04 ³ 03 ³ 02 ³ 01 ³ 00 ³ ÀÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ You may now test the bits individually, or perform an instruction similar to the follow to get an individual flag: EG: LAHF SHR AH, 6 AND AH, 1 ; AH now contains the ZF flag. þ LEA , - Name: Load Effective Address Type: 8086+ Description: This instruction loads the memory address that resides in, into . EG: I use LEA SI, Str in a procedure of mine which puts a string on the screen very fast. þ LOOP