Distributed By The American Virus Creation and Research Society An introduction to ASM (2) Please read Errata, AVCR-02.001. The Five Groups of Registers: Data Registers: Used to store and calculate numbers, the data registers consist of 2 8 bit (high and low) locations on the processor, thus the ?X registers are 16 bits. AX <-- Accumulator Register, used for simple arithmatic and number storage. BX <-- Base Register. CX <-- Count Register, used to "count," LOOP along with many other statements use the CX to do its necessary counting job. DX <-- Data Register. Offset Registers: SI <-- Index Register DI <-- Index Register SP <-- Stack Register BP <-- Stack Register IP <-- Instruction Pointer Register Segment Registers: CS <-- Code Segment Register DS <-- Stack Segment Register SS <-- Data Segment Register ES <-- Extra Segment Register Flag Registers: FL <-- Flag Set Register Simulator Registers: IR <-- Instruction Register EA <-- Effective Address Register OR <-- Offset Register SR <-- Segment Register AD <-- Address Latch Register Z <-- Data Latch Register Communication between chip and memory registers AB <-- Address Bus Register DB <-- Data Bus Register These are all of the Registers on the 80x86 chip, and you must become familiar with each one and its function and use. Hexidecimal Counting: One hexidecimal (HEX) symbol is equal to 4 bits of binary numbers. 00000000 in binary would be 00 in hexidecimal, lets take a closer look: Decimal Binary Hexidecimal 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Since the highest 4 bit binary number can be 1111 (15) then the highest hexidecimal number can be a symbol representing 1111 (15), because hex represents 4 bits of binary. How would you write 11111111 in hex, lets examine this: 11111111 Lets break this down into two 4 bit parts 1111-1111 And lets represent each part with a hex symbol FF There is your answer. To figure out what FF is easily you take: 15*16+15 Because 15 is F and one 16 bit number is being represented, and we add the missing 15. What would FE be in decimal. F is 15 and E is 14 15*16+14 is 254. Lets check our work... 1111=f 1110=e so: 11111110 is our number which is 254 in decimal, it works! The CMP, JE, JNE, and JMP Statements: If you have ever programed in a high level language then you know how important an IF...THEN then statement is. The CMP statement is how you would make an IF...THEN statement in ASM. Here is an example. LOC_0: CMP AX,BX ; Compare the AX register to the BX register. JE LOC_1 ; IF they are equal THEN jump to LOC_1 JNE LOC_2 ; IF they are not equal THEN jump to LOC_2 LOC_1: ; Location 1 in the program END LOC_2: ; Location 2 in the program DEC AX ; Subtract 1 from the AX register JMP LOC_0 ; Jump to location 0 The Keyboard Interrupt: The keyboard has its own microprocessor in it, so it will send a signal telling the main chip when a key has been pressed, and which key it was. The keyboard's hardware interrupt address is 60h or 01100000b. You would read a keystroke by calling: IN AX,60 Notice that the h is not necessary in the calling of a hardware interrupt. This places the necessary information from the keyboard into the AX register. The DB and the DD statements: The DB statement tells the computer to define one or more bytes. The syntax for the DB statement is as follows: name db 'statement' This defines name as statement, so everytime you make reference to name it treats it as statement. The DD statement defines a double word, and its syntax is similar to the DB's syntax, DW defines a word, and when a ? is added it defines ? bytes. The LOOP statement: The LOOP statement loops to a specified location as many times as the CX register can be decremented before the ZF is set. When you use the LOOP statement you must move into the CX register the number of times you would like to loop. Lets take a closer look: MOV CX,ff ; Move ff hex (255) into the CX register. LOC_1: LOOP LOC_1 ; Loop will loop [CX] times. Thus is another installment of An Introduction to ASM. I believe that another installment will be needed, for we have yet to cover many important issues. Keep your eye out for our next issue of The Journal of the AVCR, and An Introduction to ASM (3). Have a question? Email me on The Gallows Pole BBS, or write to our P.O. Box listed in the index file. Written By: Th Patron