As part of a first year university course in computer architecture some time ago we were tasked with learning 8086 ASM. The final course work required creating a small animation of shapes moving around the screen changing colours and the like.
As I would not expect anyone to review 720 lines of assembler I'm just going to provide my implementation of Bresenham's Line Algorithm.
Note that this is not the entire program but a single macro from the working program.
Also note that at the time of writing I had little to no experience with 8086 ASM (I still don't in fact), but I'm very interested in knowing how I did and how it could have been improved upon.
If anyone is interested in reviewing the rest of the project as well (it can be done in small parts) then let me know.
;=========================================================================================================
; BRESENHAM LINE ALGORITHM (lx1,ly1)-(lx2,ly2)
;=========================================================================================================
line macro lx1, ly1, lx2, ly2
local ldxsetup1, ldxsetup2, ldysetup1, ldysetup2
local lxisetup1, lxisetup2, lxisetupexit, lyisetup1, lyisetup2, lyisetupexit
local numsetup1, numsetup2, numsetupexit
local lloopstart, lloopif, lloopifexit, lloopend
pushall
mov ax, lx2
sub ax, lx1
cmp ax, 0
jge ldxsetup2
ldxsetup1:
mov bx, -1
mul bx
ldxsetup2:
mov ldx, ax
mov ax, ly2
sub ax, ly1
cmp ax, 0
jge ldysetup2
ldysetup1:
mov bx, -1
mul bx
ldysetup2:
mov ldy, ax
mov ax, lx1
mov lx, ax
mov ax, ly1
mov ly, ax
mov ax, lx2
cmp ax, lx1
jge lxisetup1
jmp lxisetup2
lxisetup1:
mov ax, 1
jmp lxisetupexit
lxisetup2:
mov ax, -1
lxisetupexit:
mov lxi1, ax
mov lxi2, ax
mov ax, ly2
cmp ax, ly1
jge lyisetup1
jmp lyisetup2
lyisetup1:
mov ax, 1
jmp lyisetupexit
lyisetup2:
mov ax, -1
lyisetupexit:
mov lyi1, ax
mov lyi2, ax
mov ax, ldx
mov bx, ldy
cmp ax, bx
jge numsetup1
jmp numsetup2
numsetup1:
mov ax, 0
mov lxi1, ax
mov lyi2, ax
mov ax, ldx
mov lden, ax
mov lnumpix, ax
shr ax, 1
mov lnum, ax
mov ax, ldy
mov lnumadd, ax
jmp numsetupexit
numsetup2:
mov ax, 0
mov lxi2, ax
mov lyi1, ax
mov ax, ldy
mov lden, ax
mov lnumpix, ax
shr ax, 1
mov lnum, ax
mov ax, ldx
mov lnumadd, ax
numsetupexit:
mov ax, lnum
mov dx, 0
lloopstart:
cmp dx, lnumpix
jg lloopend
plot lx, ly
add ax, lnumadd
cmp ax, lden
jge lloopif
jmp lloopifexit
lloopif:
sub ax, lden
mov bx, lx
add bx, lxi1
mov lx, bx
mov bx, ly
add bx, lyi1
mov ly, bx
lloopifexit:
mov bx, lx
add bx, lxi2
mov lx, bx
mov bx, ly
add bx, lyi2
mov ly, bx
inc dx
jmp lloopstart
lloopend:
popall
endm
;=========================================================================================================
Here's the definitions of pushall and popall:
;=========================================================================================================
; PUSH ALL DATA TO STACK
;=========================================================================================================
pushall macro
push ax
push bx
push cx
push dx
endm
;=========================================================================================================
;=========================================================================================================
; POP ALL DATA FROM STACK
;=========================================================================================================
popall macro
pop dx
pop cx
pop bx
pop ax
endm
;=========================================================================================================