GeoCitesSites.com

Old annotations


back home

  Assembly  (for beginners)
Size
Key directive sentences
Interupts & Services
Groepering en begrippen (NL)
  Linux on the visual tour...

  OPL (psion)

 
Assembly

Instructions (Mnemonics to CPU)

MOV   copy
NEG   verm. met -1
JMP   go-to
XCHG   verwissel
INC   +1
DEC   -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
 Derectives (instructions to the Assembler)
 DB,DW,DD define variabel-size
 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
 END  programma-einde
 Overrides (instructions to the Mnemonics)
 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


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's
 21H DOS service dispatcher
 10H BIOS video display service
 16H BIOS keyboard service
 17H BIOS printer service
DOS service's
09H print string
     load in AH
     adress of the string in DS :DX
     requires a $-sign at end of the string
     run INT 21H
     -->display a single line (the string in DS :DX)
4CH terminate process
     load in AH
     run INT 21H
     -->places the value of AL in DOS ERRORLEVEL

BIOS service's
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

Groeperingen en begrippen
    Soorten stelsels.
         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).
         assumption, overrided
    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

Linux application sugestion
Visual Tcl/Tk (v1.10) + Tcl (v7.6) + Tk (v4.2)
Visual Gipsy (commercial version of vtcl/tk
Tcl Pro (extention for testing and optimizing code)  incl.: graphical debuggen, code checker, etc
Motif (mostly with CDE wm from OSF)
Lesstif (a free clone of OSF/motif)
OPL
LOCAL x,y,z
LOCAL a%(5) (array of integer variables)
LOCAL a(5) (array of floating-point variables)
LOCAL a$(5,8) (array of string variables)
LOCAL a&(5) (array of long integers)

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.

 
DO...UNTIL:
PROC test: 
  LOCAL a% 
  a%=10 
  DO 
    PRINT "A=";a%
    a%=a%-1
  UNTIL a%=0 
  PRINT "Finished"
  GET 
ENDP 
WHILE...ENDWH:
PROC test2:
  LOCAL a%
  a%=10
  WHILE a%>0
    PRINT "A=";a%
    a%=a%-1
  ENDWH
  PRINT "Finished"
  GET
ENDP 
Example using IF:
PROC zcode:
  LOCAL g%
  PRINT "Are you going to press Z?"
  g%=GET
  IF g%=%Z OR g%=%z
    PRINT "Yes!"
  ELSE
    PRINT "No."
  ENDIF
  PAUSE 60 
ENDP 


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 
  VECTOR p%
    FUNCA,FUNCX
    FUNCR
  ENDV
  PRINT "p% was not 1/2/3" :GET :STOP 
FUNCA:: 
  PRINT "p% was 1" :GET :STOP 
FUNCX:: 
  PRINT "p% was 2" :GET :STOP 
FUNCR:: 
  PRINT "p% was 3" :GET :STOP 
syntax:
VECTOR int%
  label1, label2
  label3...
ENDV 
...
label1::
...
label2::
...
label3::
...


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:
PROC price_2:
  LOCAL x,r
  PRINT "ENTER PRICE",
  INPUT x
  PRINT "ENTER TAX RATE",
  INPUT r
  tax2:(x,r)
  GET
ENDP
PROC tax2:(p1,p2)
  PRINT p1+p2 %
ENDP