Assembly (for beginners)Linux on the visual tour...Size
Key directive sentences
Interupts & Services
Groepering en begrippen (NL)
Instructions (Mnemonics to CPU)
MOV copyDerectives (instructions to the Assembler)
NEG verm. met -1
LEA copy adress ipv waarde
CALL oproepen van een procedure
RET return to caller (from proc)
INT call interupt
IRET interupt call return
PUSH push a register to stack (DECrease)
PUSHF push a flag register to stack
POP pop value, adress off stack (INCrease)
POPF idem but for flags
DB,DW,DD define variabel-sizeOverrides (instructions to the Mnemonics)
ASSUME specifies type of segment
SEGMENT afsluiten met ENDS declarations, etc
PROC afsluiten met ENDP proceduresb
naam: label: marked location by ":"
DUP duplicate, vergelijkbaar met verminigvuldig in declaraties
BYTE PTR tel the instr. what size (NEG, INC, DEC, NOT)
WORD PTR tel the instr. what size (NEG, INC, DEC, NOT)
(DB,DW,DD) define variabel-size
Stack : 64K
Debug dump block : 128bytes
Debug dump line : 16bytes
Interupt Vector Table : 256entries * 4b/entry = 1024bytes
1charter (alg.) : 1byte
1 charter on screen in video buffer : 2bytes
AX 16bit / AL 8bit / CF 1bit / CS 16bit
Full adress (CS :IP) : 20bit effective, 32bit real.
EOL marker (CR,LF) : 2bytes (0D,0A)
EOF marker : 1byte (1A)
1M : 1048576bytes
1segment : 65536bytes of 64k
Flag register : 16bytes (9bytes used, 7b NU)
max asembly source code : 1segment
min stack allocation : 512bytes
normal DOS hercules screen : 79x24 (X,Y) counting from 0.
Key derective sentences
1. Then individual steps are very simple. It takes a lot of steps to do anything useful. The key to assembly is understanding memory adresses.
2. In programming circles ; always begin counting from nul !
3. Hexadecimaal is het verkorte voor binair.
4. Comments in source code begin at semicolons and end at an EOL marker ; they get not copied into your object code files.
5. The error message from the assembler may be almost no help at all.
6. Ignore a error warning only if you know exactly what it means !
7. General-purpose reg. Are used to hold offset adresses that must be paired with segment reg.
8. Instead of the 'X' a half is specified with 'H' or 'L' and each is one byte in size.
9. CS'code' = the adress of the current executing instruction ; DS'data' = variables and other ; SS'stack' = temp storage of data and adresses ; ES'extra' = a spare location in memory ; IP'instr.pointer' = 'offset' of next machine instr. to be executed
10. Full 20-bit adress of the next instruction is kept in CS :IP. The start adress of the video refresh buffer is 0B800 :0 if you use monochrome it is 0B000 :0. The BIOS date at adress FFFF :0005 its cold boot JMP instruction at FFFF :0000. All mem. between SS :0 and SS :SP is considered free stack space.
11. Sommetimes while looking at the dump, only the first line of memory shown really exists !
12. Debug's 'G' command executes programs in mem. starting at CS :IP, while the 'T' command executes the single instruction at CS :IP.
13. Most significant, high half, left part. Least significant, low half, right part.
14. Only BP,BX,SI and DI may hold an offset for memory data. Every reference to mem. data includes an assumed segment (DS) or a segment override prefix.
15. The 'real' machine-code which comprimise with the Mnemonics we call : instructions opcode.
16. a Machine cycle is one pulse of the master clock that makes the PC perform its magic.
17. Flag etiquette is a highly individual matter. Check the reference for each instr. to see it affects the flags. Assume nothing abouth this matter !
18. The value of a sement label is the segment adress of the named segment. Every label represents some offset adress from the segment adr. above.
19. Don't use empty variables, it helps to spot it in a debug dump of memory rather than have to find it 'dead rockoning'. at least use a definition like 'var' or ' ?'.
20. Knowing 'where' thing are is the greatest part of all your work in assembly !
21. No assembly witouth a starting label bvb 'begin :' that is redifine et the verry end of the source-code following the END directive. The POP and PUSH stack instructions work only on word-size operands. DB 64 DUP ('12345678') ;this reserves 64*8=512 bytes for the stack.
22. CALL work with RET and INT with IRET ; don't get those twoo confused !
23. Slots in the Interupt Vector Table are adresses of ISR's & ISD's. HW int's uses ISR (service routine). SW int's uses ISD (service dispatcher).
24. Assume does not load the Data Segment adress, but only specifies that 'MyData' (pag.183) is the data segment. Loading goas via MOV AX,... & MOV DS,AX.
25. Needed to display a single line : adress of the string in DS :DX ; service nr 09 in AH ; INT 21H
26. Typical screen-size in Turbo Pascal is 80x25, the Bios would use 79x24 starting from 0 ipv 1.
27. Avoid dropping immediate values into code (=hard-coding) ; use variables !
Interupts & services
Software interupt'sDOS service's
21H DOS service dispatcher
10H BIOS video display service
16H BIOS keyboard service
17H BIOS printer service
02H position cursor
load in AH
load X in DL(max79) and Y in DH(max24)
MOV BH,0 (unles you intend to use multiple display pages)
run INT 10H
-->clear screen and cursor jump to X,Y (DX) ; zia pag.225
06H initialize scroll
load in AH
frame: UL-X in CL, UL-Y in CH, LR-X in DL, LR-Y in DH
vb: MOV CX,0422H ;X=22H ;Y=04H
MOV DX,093AH ;X=3AH ;Y=09H
amount of lines that can be scrolled in AL, 0 specifies to clear the entire screen
text display attribute in BH (07 is normal)
run INT 10H
-->clear screen and enables scroll in frame ; zie pag.227-229
decimaal, hexadecimaal, binair, octomaal
Commando's in asembly.
instructions, directives, overrides
Development : linkage & compilation.
source, object, executable
Soorten CPU registers.
segment , general-purpose (wholes&halves), instruction pionter, flags
Soorten assembly data.
memory data, register data, immediate data
Left & right byte of register halves.
most significant byte (msb) = high, least significant byte (lsb) = low
Memory data, adressing the segment (assumed DS).
Non commands in assembly.
labels, variables, string variables
Aanroepen interupts (Dos, Bios sevices) and (IRQ's).
software interupts, hardware interupts
Source code segments.
stack, data, code
Visual Tcl/Tk (v1.10) + Tcl (v7.6) + Tk (v4.2)
Linux application sugestion
GET$ waits for a keypress and returns the key
pressed, as a string.
KEY$ returns a key if any was pressed, but doesn't wait for one. KEY$ returns a null string if no key was pressed.
Example using IF:
PRINT "Are you going to press Z?"
IF g%=%Z OR g%=%z
Jumping out of a loop: BREAK
Jumping to a 'label': GOTO [label]
Jumping to the previous nested test condition: CONTINUE
Vectoring to a label: VECTOR/ENDV
PRINT "p% was not 1/2/3" :GET :STOP
PRINT "p% was 1" :GET :STOP
PRINT "p% was 2" :GET :STOP
PRINT "p% was 3" :GET :STOP
the STOP-command stops a running program completely.
The same effect as using GOTO to jump to a label above the final ENDP.
Call a Procedures with parameters:
PRINT "ENTER PRICE",
PRINT "ENTER TAX RATE",
PRINT p1+p2 %