Intro - BBC Micro Assembly
When I was a child (a long time ago) I used to program a BBC Micro (or "Beeb") circa 1982. A Beeb had two programming languages, BBC Basic and 6502 Assembly language because it had a 6502 CPU. Nearly all the programs from those days were typed in from a magazine like BBC Micro User, most of them were BBC Basic but some had an assembly section delimited by square brackets to speed up, here is an example taken from this screenshot
>10 oswrch=&FFEE
>20 DIM memory% 100
>30 FOR Z=0 TO 3 STEP 3
>40 [OPTZ
>50 .start LDA#ASC"!"
>60 LDX #40
>70 .loop jsr oswrch
>80 dex:BNE loop
>90 rts:] NEXT Z
>100 CALL start
>110 END
I couldn't tell you what the above program does, it was a long time ago. But I can tell you that a high level programmer takes for granted writing an expression such as a=b+c. Under the hood the expression is translated into assembly operations: an accumulator is loaded with a memory call to the address of b and the same accumulator accumulates (hence its name) the sum with a memory call to the address of c and then the result is stored in the memory address of a.
So it's about marshalling data from memory into a register, doing an op and then storing the result. You may think 'so what'? But sometimes, a discussion of C/C++ compilers descends into assembly language and it is nice to have an inkling of how it works. But better to turn now to Intel Assembly Language.
Intel - x86 and x64 Assembly
So I won't reproduce the contents of the following links but will keep some notes. First the links.
- De Pauw Uni - Assembly Tutorial - Registers
- Uni of Alaska Fairbanks - x86_64 NASM Assembly Quick Reference ("Cheat Sheet")
- Brown University - x64 Cheat Sheet
- Brigham Young Uni - 8086 Assembly Language
Registers
Section | 16 bit Code | Desc | Long Desc | 32-bit | 64-bit |
---|---|---|---|---|---|
General Purpose Registers | AX | Accumulator | Main arithmetic register | EAX | RAX |
BX | Base | Generally used as a memory base or offset | EBX | RBX | |
CX | Counter | Generally used as a counter for loops | ECX | RCX | |
DX | Data | General 16-bit storage, division remainder | EDX | RDX | |
Offset Registers | IP | Instruction pointer | Current instruction offset | ||
SP | Stack pointer | Current stack offset | ESP | RSP | |
BP | Base pointer | Base for referencing values stored on stack | EBP | RBP | |
SI | Source index | General addressing, source offset in string ops | ESI | RSI | |
DI | Destination index | General addressing, destination in string ops | EDI | RDI | |
Segment Registers | CS | Code segment | Segment to which IP refers | ||
SS | Stack segment | Segment to which SP refers | |||
DS | Data segment | General addressing, usually for program's data area | |||
ES | Extra segment | General addressing, destination segment in string ops |
Flags Register (Respectively bits 11,10,9,8,7,6,4,2,0)
OF Overflow flag : Indicates a signed arithmetic overflow occurred
DF Direction flag : Controls incr. direction in string ops (0=inc, 1=dec)
IF Interrupt flag : Controls whether interrupts are enabled
TF Trap flag : Controls debug interrupt generation after instructions
SF Sign flag : Indicates a negative result or comparison
ZF Zero flag : Indicates a zero result or an equal comparison
AF Auxiliary flag : Indicates adjustment is needed after BCD arithmetic
PF Parity flag : Indicates an even number of 1 bits
CF Carry flag : Indicates an arithmetic carry occurred
Why do registers matter? It would appear that it is possible to get a compiler to pass variables not via the stack but via registers for extra speed. See Intel's C/C++ Calling Conventions.
No comments:
Post a Comment