ASSEMBLER LANGUAGE TUTORIAL
BIT, BYTE AND WORD
HEXADECIMAL SYSTEM
CONVERTING DECIMAL TO HEXADECIMAL NUMBERS
THE INTEL PROCESSOR
MSB LSB 15 0 _________________________ | A X | AX is a 16 bit register, AL and AH | AH | AL | are 8 bit registers. The same |_________________________| applies for BX, BL, BH, CX, CL, | B X | CH, DX, DL and DH. | BH | BL | |_________________________| These registers are called | C X | common registers. | CH | CL | |_________________________| | D X | | DH | DL | |_________________________| | SI | SI and DI are string registers used |_________________________| for copying and comparing strings, | DI | i.e., password protections. |_________________________| | SP | SP and BP are stack registers. |_________________________| I'll get to the stack later. | BP | |_________________________| | CS | CS, DS, ES and SS are SEGMENT |_________________________| registers. | DS | |_________________________| | ES | |_________________________| | SS | |_________________________| _________________________ | IP | Instruction Pointer |_________________________| | O D I T S Z A P C | Flags |_________________________|
segment offset (IP) \ / 013F:0012So the segment keeps track of which 64Kb block you are in and the IP keeps track of where in that block you are (offset). The segment address depends on the amount of memory that is free. This means that your program will be given different segment addresses if you change your memory (like loading another program). The offset address is always the same.
THE INSTRUCTIONS SET
THE INTERRUPTS
Function AH In data ---------------- -- ---------- Output to screen 02 char in DL
MOV AH,02 ; Put the service number in AH MOV DL,41 ; ASCII number for "A" in hex INT 21 ; Execute interrupt
DOSSEG ; We are using DOS segment .MODEL SMALL ; Defines how much memory our program needs .STACK 100h ; Reserves 100h bytes for the stack .DATA ; Under this we shall put our variables MESSAGE DB 'Hello world',13,10 ; Our message .CODE ; This is where our program starts MOV AX,@DATA ; Put the address of the data in AX MOV DS,AX ; And then move it to DS MOV AH,9 ; Select DOS int 21 output service MOV DX,OFFSET MESSAGE ; Put the offset of MESSAGE in DX INT 21 ; Print the message on the screen MOV AH,4C ; Select service to quit and exit to DOS INT 21 ; And execute it END ; End of the program
Function Num In/out data -------------------- --- ----------------------------------------- Input from keyboard 01 AL contains the typed char after with echo to screen the int has been executed. Print char on screen 02 DL contains the char to be printed. Print string 09 The segment:offset of the string on screen is taken from DS:DX. Create file 3C CX attributes of the file, DS:DX pointer to the name of the file. Returns AX handle or error code. Open file 3D AL access and sharing modes, DS:DX file name. Returns AX handle or error code. Read from file 3F BX handle, DS:DX pointer to data buffer. Returns AX number of bytes read or error code. Write to file 40 BX handle, CX number of bytes to write, DS:DX pointer to data buffer. Returns AX number of bytes written or error code.
dosseg .model small .stack 200h .data password db 'fender','$' ; The strings and data we shall use login db 100 dup (0) rig db 'correct','$' .code mov ax,@data mov ds,ax mov ah,3fh ; Read function from int 21 mov bx,0 ; Handle 0 (keyboard) mov cx,3 ; Just check the 3 first letters mov dx,offset login ; Offset in DX int 21h and ax,ax ; See if something was typed in jz fin ; No? So end mov cx,ax ; Move the number of bytes read into CX mov ax,seg login ; Put segment address in AX mov es,ax ; So we can put it in ES mov ax,seg password ; Same here but with another string mov ds,ax ; And store it in DS mov di,offset login ; Do the same with the offsets mov si,offset password ; of both strings repe cmpsb password,login ; Compare them je equals ; If equal then go to equals fin: ; End program function mov ah,4ch int 21h equals: ; Subroutine for strings equal mov dx,offset rig mov ah,9 int 21h ret end
SOFTICE DOS VERSION 2.62
AQUANOID
CS:39A9 FF8C44AC DEC WORD PTR [SI+AC44],+00
FF8C44AC DEC WORD PTR [SI+AC44],+00
INTERESTING LINKS