Back to index |
Assembly language is the closest thing you come to machinde code. It's a low level
language which means that isn't as intelligent as high level languages like C or pascal. It's
harder to code in than those programs, but it runs much faster and you have total
control of what you are doing. You shouldn't write programs all in assembly but use it as inline
assembly in high level languages where you want it to run faster.
There are four 32 bit registers called eax, ebx, ecx and edx. These registers can also be
used as 16 bit registers: ax, bx, cx, dx. The 16 bit registerscan be split up into two 8 bit
registers which for ax are called ah and al. ah is the highest 8 bits in ax and al is the
lowest 8 bits.
mov ax,17
This will move 17 into ax, then move the contents of ax into dx and move dx into mem. To add or subtract a constant or a register you can do this
add ax,4
If you want to add or subtract 1 use inc and dec
inc ax
There are also 6 segment registers called cs, ds, es, fs, gs and ss. To access a memory you need both a segment and an offset. si and di are index registers and can be used as offsets. So when you want to access memory you can do it like this mov al,ds:[si] cs is the code segment and should always point to this segment. The CPU executes instructions at cs:ip. ip is the instruction poiner. ds is the data segment. This is where your data are. es, fs and gs are extra segment registers. You can use lodsb to load a byte from ds:si into al. lodsw loads a word into ax and
lodsw loads a doubleword into eax. These instructions adds 1, 2 or 4 to si.
mov cx,100
You can also use rep stosw and rep stosd to store a word or a doubleword. To compare a register with another register, a constant or memory use the cmp instruction. After you've compared something you can use jumps to act on the compare.
je somewhere
jne somewhere
ja somewhere
jb somewhere
somewhere is defined by typing somewhere: in the program. Interrupts can be used to handle files or to change the screen or to put text on the screen. You call interrupts like this
mov ax,0003h
This will put you in textmode. int 10h is the screeen interrupt. It would be a good idea to download a list of all interrupts and their functions. This is the most common instructions. Download a full list of the instructions at www.intel.com |
Jesper L. Poulsen |