Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FLOAT_SIZE = 20
- data segment
- argNumbers db 0
- cmdLine db 80h dup (?)
- newLine db 13, 10, '$'
- floatTmp db FLOAT_SIZE dup (?)
- coprocPassQ dq ?
- coprocPassD dd ?
- coprocPassW dw ?
- RES_X dw 320
- RES_Y dw 200
- ITERATIONS dw 1000
- ten dd 10.0
- negativeOne dd -1.0
- condition dd 4.0
- two dd 2.0
- numbers:
- xmin dq ?
- xmax dq ?
- ymin dq ?
- ymax dq ?
- cr dq ?
- ci dq ?
- zr dq 0.0
- zi dq ?
- tmp dq ?
- zero dq 0.0
- ; Messages
- wrongData db "Wprowadzono nieprawidlowe liczby.$"
- wrongNumber db "Nalezy wprowadzic dokladnie 6 liczb w formacie 123.456.$"
- data ends
- code segment
- .386
- .387
- assume cs:code, ds:data, ss:stack
- start:
- call dataInit
- push offset argNumbers
- push offset cmdLine
- call getCmdLine
- add sp, 4
- cmp ds:[argNumbers], 6
- jne not6Numbers
- push offset cmdLine
- push offset numbers
- push 6
- call strToFloats
- add sp, 6
- cmp ax, 0
- jne exitProgram
- call drawSet
- cmp al, 0
- jne exitProgram ; ERROR CHECK
- mov al, 0
- exitProgram:
- mov ah, 4ch ;exit code
- int 21h
- not6Numbers:
- mov ah, 9h
- mov dx, offset wrongNumber
- int 21h
- mov ax, 2
- jmp exitProgram
- ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ; DATA INIT * * * * * * * * * * * * * * * * * * * * * * * * * * *
- dataInit proc
- mov dx, seg data ;data segment initialization
- mov ds, dx
- mov ax, seg stack ;stack initialization
- mov ss, ax
- mov sp, offset topStack
- finit
- ret
- dataInit endp
- ; GET CMD LINE* * * * * * * * * * * * * * * * * * * * * * * * * *
- getCmdLine proc
- ;[AX, CX, DX, BX, SP, BP, SI, DI][ret][command line ptr][argument numbers ptr]
- ;^
- pusha
- mov bp, sp
- mov ah, 62h
- int 21h ; int 21h with 62h returns PSP structure
- mov es, bx ; es = bx (the PSP address)
- mov cx, es:[80h]
- mov di, [bp + 18] ; di = command line address
- cmp cl, 0
- jz exitGetCmdLine
- mov si, 82h ; si = 82h - first character from command line in the PSP structure
- mov cx, 1
- loopCmdLine:
- mov al, es:[si]
- cmp al, 0dh
- jz exitGetCmdLine
- cmp al, ' '
- jz removeWhite
- cmp al, 9h
- jz removeWhite
- mov byte ptr [di], al
- inc di
- inc si
- jmp loopCmdLine
- exitGetCmdLine:
- mov al, 7h
- mov byte ptr ds:[di], al
- mov ax, [bp + 20]
- mov di, ax
- mov byte ptr ds:[di], cl
- popa
- ret
- removeWhite:
- cmp byte ptr [di-1], 7h
- je removeWhiteCon
- mov byte ptr [di], 7h
- inc di
- inc cl
- removeWhiteCon:
- inc si
- jmp loopCmdLine
- getCmdLine endp
- ; STR ARRAY ELEMENT * * * * * * * * * * * * * * * * * * * * * * *
- getStringArrayElement proc
- ;[cx][bp][di][si][ret][str to save][index][array size][source str array]
- ;^
- push si
- push di
- push bp
- push cx
- mov bp, sp
- mov ax, ss:[bp+14] ; ax = array size
- dec ax
- cmp ss:[bp+12], ax ; cmp: index and array size [AX]
- jg getStringError ; if index > array size => error
- mov cx, ss:[bp+12] ; cx = index
- mov si, ss:[bp+16] ; si = source str array
- mov di, ss:[bp+10] ; di = str to save
- cmp cx, 0
- je copyStringElement
- dec si
- goToIndex: ; setting si in the source array
- inc si
- cmp byte ptr ds:[si], 7h
- jne goToIndex
- dec cx
- cmp cx, 0
- jne goToIndex
- inc si
- copyStringElement: ; copying array element to the string destination
- mov al, byte ptr ds:[si]
- mov byte ptr ds:[di], al
- inc si
- inc di
- cmp byte ptr ds:[si], 7h
- jne copyStringElement
- mov byte ptr ds:[di], 7h ; array terminator (convention)
- jmp getStringArrayElementExit
- getStringError:
- mov al, 2
- getStringArrayElementExit:
- pop cx
- pop bp
- pop di
- pop si
- ret
- getStringArrayElement endp
- ; STR TO FLOATS * * * * * * * * * * * * * * * * * * * * * * * * *
- strToFloats proc
- ;[dx][cx][bp][di][si][ret][elements to load][offset dst array][offset source array]
- ;^
- push si
- push di
- push bp
- push cx
- push dx
- mov bp, sp ; bp = sp
- mov cx, ss:[bp+12] ; cx = elements to load
- mov di, ss:[bp+14] ; di = offset dst array
- mov si, ss:[bp+16] ; si = offset source array
- mov di, offset xmin
- mov ax, 0
- loadArrayLoop:
- push ax
- push si
- push 80h
- push ax
- push offset floatTmp
- call getStringArrayElement
- add sp, 8
- push di
- push offset floatTmp
- call convertStringToFloat
- add sp, 4
- cmp ax, 0
- jne strToFloatsExitA
- add di, 8
- pop ax
- inc ax
- dec cx
- jnz loadArrayLoop
- mov ax, 0
- jmp strToFloatsExitB
- strToFloatsExitA:
- add sp, 2
- strToFloatsExitB:
- pop dx
- pop cx
- pop bp
- pop di
- pop si
- ret
- strToFloats endp
- ; CONVERT STRING TO FLOAT * * * * * * * * * * * * * * * * * * * *
- convertStringToFloat proc
- ;[di][si][bp][cx][ret][offset str source][offset dst float]
- ;^
- push cx
- push bp
- push si
- push di
- mov bp, sp
- mov si, ss:[bp+10] ; si = float number (string)
- mov di, ss:[bp+12] ; di = destination memory for float number
- fld ten
- fldz ; st(0) = 0.0, st(1) = 10.0
- cmp byte ptr ds:[si], '-' ; omitting '-' symbol
- jne str2floatA
- inc si
- str2floatA: ; integer part conversion
- mov ah, 0
- mov al, byte ptr ds:[si]
- cmp al, '.'
- je str2floatB
- cmp al, '0' ; checking whether it contains only decimal digits
- jl wrongChar
- cmp al, '9'
- jg wrongChar
- sub al, '0'
- mov word ptr ds:[coprocPassW], ax
- fmul st, st(1)
- fiadd coprocPassW
- inc si
- jne str2floatA
- str2floatB: ; getting to the end of the number
- inc si
- cmp byte ptr ds:[si], 7h
- jne str2floatB
- dec si
- fstp st(2) ;st => st(2)
- fldz ;st = 0, st(1) = 10.0, st(2) = old st
- str2floatC: ; decimal part conversion
- mov ah, 0
- mov al, byte ptr ds:[si]
- cmp al, '.'
- je str2floatOut
- cmp al, '0' ; checking whether it contains only decimal digits
- jl wrongChar
- cmp al, '9'
- jg wrongChar
- sub al, '0'
- mov word ptr ds:[coprocPassW], ax
- fiadd coprocPassW
- fdiv st, st(1)
- dec si
- jne str2floatC
- str2floatOut:
- fadd st, st(2) ; adding integer and floating point part
- mov si, ss:[bp+10] ; si = float number (string)
- cmp byte ptr ds:[si], '-' ; if it's a negative number...
- jne convCont
- fmul negativeOne ; it's being multiplied by negative one (-1.0)
- convCont: ; copying number to tmp variable in memory (coprocPassQ)
- fstp coprocPassQ
- mov si, offset coprocPassQ ; copying number from coprocPassQ to destination variable
- mov cx, 8
- push es
- mov ax, ds
- mov es, ax
- cld
- rep movsb
- pop es
- mov ax, 0
- exitStrToFloatConv:
- faddp st, st
- pop di
- pop si
- pop bp
- pop cx
- ret
- wrongChar: ; error check
- mov ah, 9h
- push dx
- mov dx, offset wrongData
- int 21h
- pop dx
- mov ax, 3
- jmp exitStrToFloatConv
- convertStringToFloat endp
- ; DRAW SET* * * * * * * * * * * * * * * * * * * * * * * * * * * *
- drawSet proc
- ;;[AX, CX, DX, BX, SP, BP, SI, DI][ret][offset numbers]
- ;^
- pusha
- mov ah, 0 ; graphic mode
- mov al, 13h
- int 10h
- mov ax, 0A000h
- mov es, ax ; es = VGA memory
- mov al, 0
- mov di, 0
- mov bx, 0
- loopY:
- push bx
- call calculateIm
- add sp, 2
- mov dx, 0
- loopX:
- push dx
- call calculateRe
- add sp, 2
- call discrepancy
- ; 320 = 256 + 64 = 2^8 + 2^6
- ; di = 320*y + x = 2^8*y + 2^6*y + x
- push ax
- mov ax, bx
- mov di, bx
- shl di, 8
- shl ax, 6
- add di, ax
- add di, dx
- pop ax
- cmp al, 1
- je blackPixel
- mov al, 31
- mov byte ptr es:[di], al ; putting white pixel
- jmp loopContinue
- blackPixel:
- mov al, 0
- mov byte ptr es:[di], al ; putting black pixel
- loopContinue:
- inc dx
- cmp dx, word ptr ds:[RES_X]
- jne loopX
- inc bx
- cmp bx, word ptr ds:[RES_Y]
- jne loopY
- mov ah, 7h ; "get key" interruption
- int 21h
- mov al, 3 ; getting back to text mode
- mov ah, 0
- int 10h
- popa
- ret
- drawSet endp
- ; CALCULATE Re* * * * * * * * * * * * * * * * * * * * * * * * * *
- calculateRe proc
- ;[di][si][bp][ret][x]
- ;^
- push bp
- push si
- push di
- mov bp, sp
- mov ax, ss:[bp+8] ; ax = x
- mov word ptr ds:[coprocPassW], ax
- fld xmax
- fld xmin
- fild RES_X
- fild coprocPassW
- fldz ; coproc:[ 0.0 | X | RES_X | xmin | xmax ]
- ; [ 0 | 1 | 2 | 3 | 4 ]
- ; zr = xmin + x*(xmax-xmin)/RES_X
- fadd st, st(4)
- fsub st, st(3)
- fdiv st, st(2)
- fmul st, st(1)
- fadd st, st(3)
- ; passing calculeted float to variable in tmp memory
- fstp coprocPassQ
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- ; copying variable from tmp to zr
- mov si, offset coprocPassQ
- mov di, offset zr
- mov cx, 8
- push es
- mov ax, ds
- mov es, ax
- cld
- rep movsb
- pop es
- pop di
- pop si
- pop bp
- ret
- calculateRe endp
- ; CALCULATE Im* * * * * * * * * * * * * * * * * * * * * * * * * *
- calculateIm proc
- ;[di][si][bp][ret][y]
- ;^
- push bp
- push si
- push di
- mov bp, sp
- mov ax, ss:[bp+8] ; ax = y
- mov word ptr ds:[coprocPassW], ax
- fld ymax
- fld ymin
- fild RES_Y
- fild coprocPassW
- fldz ; coproc:[ 0.0 | Y | RES_Y | ymin | ymax ]
- ; [ 0 | 1 | 2 | 3 | 4 ]
- ; zy = ymin + y*(ymax-ymin)/RES_Y
- fadd st, st(4)
- fsub st, st(3)
- fdiv st, st(2)
- fmul st, st(1)
- fadd st, st(3)
- ; passing calculeted float to variable in tmp memory
- fstp coprocPassQ
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- ; copying variable from tmp to zi
- mov si, offset coprocPassQ
- mov di, offset zi
- mov cx, 8
- push es
- mov ax, ds
- mov es, ax
- cld
- rep movsb
- pop es
- pop di
- pop si
- pop bp
- ret
- calculateIm endp
- ; DISCREPANCY * * * * * * * * * * * * * * * * * * * * * * * * * *
- discrepancy proc
- ;[FLAGS][cx][ret]
- push cx
- pushf
- mov cx, word ptr ds:[ITERATIONS]
- fldz
- fldz
- fld condition
- fld zr
- fld zi
- fld cr
- fld ci
- fldz ; coproc:[ tmp | ci | cr | zi | zr | 4.0 | x*x | y*y ]
- ; [ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ]
- fxch st(6) ;x*x
- faddp st, st
- fldz
- fadd st, st(4)
- fmul st, st
- fxch st(6)
- fxch st(7) ;y*y
- faddp st, st
- fldz
- fadd st, st(3)
- fmul st, st
- fxch st(7)
- discrLoop:
- faddp st, st
- fldz
- fadd st, st(6) ;tmp = x*x - y*y + cr
- fsub st, st(7)
- fadd st, st(2)
- fxch st(3) ;zi = 2*zi*zx + ci
- fmul st, st(4)
- fmul two
- fadd st, st(1)
- fxch st(3)
- fst st(4) ;zr = tmp
- faddp st, st
- fldz
- fxch st(6) ;x*x
- faddp st, st
- fldz
- fadd st, st(4)
- fmul st, st
- fxch st(6)
- fxch st(7) ;y*y
- faddp st, st
- fldz
- fadd st, st(3)
- fmul st, st
- fxch st(7)
- fadd st, st(6) ;tmp = x*x + y*y
- fadd st, st(7)
- fist coprocPassW ;checking whether x*x + y*y > 4
- mov ax, 4
- cmp word ptr ds:[coprocPassW], ax
- jge outDiscrLoop
- loop discrLoop
- mov al, 0
- jmp exitDiscr
- outDiscrLoop:
- mov al, 1
- exitDiscr:
- faddp st, st ; clearing the coproc stack
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- faddp st, st
- popf
- pop cx
- ret
- discrepancy endp
- code ends
- stack segment stack
- dw 1000h dup(?)
- topStack dw ?
- stack ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement