![]() | Upline: Infos & Dokus
Programmierung
Assembler
Zeichnen geometrischer Figuren in x86-Assembler unter DOSHintergrund für dieses Programm ist der 1. Laborversuch des Faches Maschinenorientierte Programmierung (MoPro, 3. Semester) der Fachrichtung Technische Informatik an der FHTW Berlin. Dieses Labor wurde im WS2004 bei Prof. Schebesta durchgeführt. ProtokollVorüberlegungZiel:
benötigte Funktionen:
benötigte Variablen:
Programmablaufplan (PAP) ![]() Screenshot des Beispielprogramms ![]() Quelltext .MODEL SMALL
.STACK 512 ;stackdef
.DATA
rectmatric dw 23,02,72,23,1F41h
dw 05,02,14,05,2F42h
dw 21,14,37,19,3F43h
dw 13,06,17,09,4F44h
dw 01,12,05,15,5F45h
dw 03,02,07,03,6F46h
dw 78,00,79,12,7F47h
dw 76,13,77,25,8048h
dw 10,10,20,15,9049h
x1 dw ?
y1 dw ?
x2 dw ?
y2 dw ?
cz dw ?
;=============================================================
;=============================================================
.CODE
;=============================================================
;cls - 4 blank screen in white
;-------------------------------------------------------------
cls PROC NEAR
MOV CX,2000
MOV AX,0F020h
REP STOSW
RET
cls ENDP
;=============================================================
;rect - paint a rectangle
;call: x1,y1,x2,y2,col pushen
;no range check! x1<x2 and y1<y2 must be true!
;-------------------------------------------------------------
rect PROC NEAR
MOV BX,x2 ;transform 2. Koords in width
SUB BX,x1
INC BX
MOV x2,BX
MOV BX,y2 ;transform 2. Koords in height
SUB BX,y1
INC BX
MOV y2,BX
MOV DX,y1 ;set DI,(x1;y1)
SHL DX,5 ;160=2^7+2^5
MOV DI,DX
SHL DX,2
ADD DI,DX
MOV DX,x1 ;add x1
SHL DX,1
ADD DI,DX
MOV DX,y2 ;heightcounter
MOV CX,x2
@@@recty:
REP STOSW ;AX has value of color+sign from call
MOV CX,x2
ADD DI,160
SUB DI,CX
SUB DI,CX
DEC DX
JNZ @@@recty
RET
rect ENDP
;=============================================================
;main
;-------------------------------------------------------------
start:
MOV AX,@DATA
MOV DS,AX
CLD ;Direction flag -> 0, default
MOV AX,0b800h ;ES:DI @begin of textmode-mem
MOV ES,AX
XOR DI,DI
CALL cls ;blank screen
XOR DI,DI ;back to 0
MOV CX,9
mainrect:
MOV AX,DS:[DI] ;read from rectmatrix into varibles
MOV x1,AX
ADD DI,2
MOV AX,DS:[DI]
MOV y1,AX
ADD DI,2
MOV AX,DS:[DI]
MOV x2,AX
ADD DI,2
MOV AX,DS:[DI]
MOV y2,AX
ADD DI,2
MOV AX,DS:[DI] ;color in AX, used in rect
ADD DI,2
PUSH CX
PUSH DI
CALL rect
POP DI
POP CX
LOOP mainrect
MOV AX,0800h ;keypress
INT 21h
MOV AX,4c00h ;halt
INT 21h
END start
DownloadDie ausführbare Datei (nur DOS und Windows mit DOS-Unterbau, also bis Win98SE) rect.exe ist nur 778 Byte groß. |