Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- .386 ;für "groessere" jumps
- ;--------------------------------------------------------------------;
- ; Daten & Variablen
- ;--------------------------------------------------------------------;
- .data
- esc_code = 1Bh
- videospeicher = 0B800h
- adressanfang = 0F000h
- adressende = 0FA6Eh
- MSG_FIRST_NUM DB "Zahl 1: " ;10 gesamtänge
- MSG_SECOND_NUM DB "Zahl 2: " ;10 Länge
- MSG_OPERATION DB "[+ - *]: " ; 11 Länge
- RESULT_LINE DB "____________" ;17
- PLACE_HOLDER_ADD DB 0, 13, 10, 13,10,13, " $"
- PLACE_HOLDER_ADD_M DB 0, 13, 10, 13,10,13, " $"
- MSG_FAIL_NUM DB "Keine gueltige Zahl!" ;20
- MSG_FAIL_OP DB "Keine gueltige Operation!" ;25
- MSG_START_LINE db 03h
- MSG_START_TITLE db 0bh,"DER CALCULATOR",0ah ;14
- MSG_START_SUBTITLE db "Addition, Subtraktion und Multiplikation" ;40
- MSG_START_SUBSUBTITLE db "Zahlen von 00 - 99" ;18
- MSG_MAN_TITLE DB "Anleitung:"
- MSG_MAN_FIRST DB "1. Zahl eingeben"
- MSG_MAN_SECOND DB "2. Operation eingeben"
- MSG_MAN_THIRD DB "3. Zahl eingeben"
- MSG_START_PRESENTED db "Proudly presented to you by Kevin & Florian!"
- MSG_EXIT_RESTART db "Noch eine Runde? (j/n)" ;22 Länge
- charOne DB ?
- charTwo DB ?
- ergebnis dw ?
- operator DB ?
- temp DB ?
- num1_1 db ?
- num1_2 db ?
- num2_1 db ?
- num2_2 db ?
- ten db 10
- colorNums dw 0Ah
- colorTitle dw 09h
- colorSubTitle dw 07h
- colorPresent dw 085h
- colorLine dw 0Bh
- colorRestart dw 0Eh
- colorFail dw 0Ah
- resultE DB ?, "$"
- resultT DB ?, "$"
- resultH DB ?, "$"
- resultX DB ?, "$"
- ;--------------------------------------------------------------------;
- ; Code
- ;--------------------------------------------------------------------;
- .code
- jmp start
- ;--------------------------------------------------------------------;
- ; FEHLER
- ;--------------------------------------------------------------------;
- fehler: ;Fehlermeldung für ungueltigen Input
- mov ax, 1300h
- mov bx, colorFail
- mov dh, 19 ;ROW
- mov dl, 10
- mov cx, 20
- mov bp, offset MSG_FAIL_NUM
- int 10h
- mov cx, 900
- call delayLoop
- jmp start
- fehlerOp:
- mov ax, 1300h
- mov bx, colorFail
- mov dh, 19 ;row
- mov dl, 7
- mov cx, 25
- mov bp, offset MSG_FAIL_OP
- int 10h
- mov cx, 900
- call delayLoop
- jmp start
- delayLoop:
- mov ax, 60000
- loopx:
- dec ax
- jnz loopx
- dec cx
- jnz delayLoop
- ret
- ;--------------------------------------------------------------------;
- ; Programmstart
- ;--------------------------------------------------------------------;
- start:
- ; init ds
- mov ax, @data
- mov ds, ax
- mov es, ax
- mov ax, 3
- int 10h
- call buildUi
- mov resultE, 0
- mov resultT, 0
- mov resultH, 0
- mov resultX, 0
- ;Eingabe der ersten Zahl
- ;Interrupt Systemfunktion, 09 = Zeichenkette darstellen
- mov ax, 1301h
- mov bx, colorNums
- mov dh, 9 ;row
- mov dl, 34
- mov cx, 10 ;+2
- mov bp, offset MSG_FIRST_NUM
- int 10h
- ;Interrupt Systemfunktion, 01 = Eingabe Lesen (mit Echo)
- ;1. Stelle
- mov ah,01h
- int 21h
- mov num1_1 ,al
- ;Falsche Eingabe 1. Stelle abfangen
- cmp num1_1, esc_code
- je shutdown
- cmp num1_1 , "0"
- jl fehler
- cmp num1_1 , "9"
- jg fehler
- sub al, 48
- mov num1_1 ,al
- ;2. Stelle
- mov ah,01h
- int 21h
- mov num1_2,al
- ;Falsche Eingabe 2. Stelle abfangen
- cmp num1_2, esc_code
- je shutdown
- cmp num1_2, "0"
- jl fehler
- cmp num1_2, "9"
- jg fehler
- sub al, 48
- mov num1_2,al
- ;Zahl zusammenfügen
- mov al,num1_1
- mul ten
- add al,num1_2
- mov charOne, al
- ;Eingabe der Operation
- mov ax, 1301h
- mov bx, colorNums
- mov dh, 11 ;row
- mov dl, 34
- mov cx, 11 ;+1
- mov bp, offset MSG_OPERATION
- int 10h
- ;Operator in Variable speichern
- mov ah, 01
- int 21h
- mov operator, al
- ;Addition
- cmp operator, "+"
- je addition
- ;Subtraction
- cmp operator, "-"
- je subtraction
- ;Multiplication
- cmp operator, "*"
- je multiplication
- ;Exit
- cmp operator, esc_code
- je shutdown
- ;Failure
- jmp fehlerOp
- ;--------------------------------------------------------------------;
- ; BUILD USER INTERFACE
- ;--------------------------------------------------------------------;
- buildUi PROC
- mov temp, 1
- poop:
- mov ax, 1300h
- mov bx, colorLine
- mov dh, 1;row
- mov dl, temp
- mov cx, 1
- mov bp, offset MSG_START_LINE
- int 10h
- mov ax, 1300h
- mov bx, colorLine
- mov dh, 23;row
- mov dl, temp
- mov cx, 1
- mov bp, offset MSG_START_LINE
- int 10h
- inc temp
- cmp temp, 79
- jne poop
- mov temp, 2
- noop:
- mov ax, 1300h
- mov bx, colorLine
- mov dh, temp;row
- mov dl, 1
- mov cx, 1
- mov bp, offset MSG_START_LINE
- int 10h
- mov ax, 1300h
- mov bx, colorLine
- mov dh, temp;row
- mov dl, 78
- mov cx, 1
- mov bp, offset MSG_START_LINE
- int 10h
- inc temp
- cmp temp, 23
- jne noop
- mov ax, 1300h
- mov bx, colorTitle
- mov dh, 2 ;row
- mov dl, 32
- mov cx, 16
- mov bp, offset MSG_START_TITLE
- int 10h
- mov ax, 1300h
- mov bx, colorSubTitle
- mov dh, 4 ;row
- mov dl, 20 ; column
- mov cx, 40
- mov bp, offset MSG_START_SUBTITLE
- int 10h
- mov ax, 1300h
- mov bx, colorSubTitle
- mov dh, 6 ;row
- mov dl, 31 ; column
- mov cx, 18
- mov bp, offset MSG_START_SUBSUBTITLE
- int 10h
- mov ax, 1300h
- mov bx, colorPresent
- mov dh, 21 ;row
- mov dl, 18 ; column
- mov cx, 44
- mov bp, offset MSG_START_PRESENTED
- int 10h
- ret
- buildUi ENDP
- ;--------------------------------------------------------------------;
- ; FUNC: READ SECOND NUM
- ;--------------------------------------------------------------------;
- readSecondNum PROC
- ;Eingabe der zweiten Zahl
- ;Interrupt Systemfunktion, 09 = Zeichenkette darstellen
- mov ax, 1301h
- mov bx, colorNums
- mov dh, 13 ;row
- mov dl, 34
- mov cx, 10
- mov bp, offset MSG_SECOND_NUM
- int 10h
- ;Interrupt Systemfunktion, 01 = Eingabe Lesen (mit Echo)
- ;1. Stelle
- mov ah,01h
- int 21h
- mov num2_1, al
- ;Falsche Eingabe 1. Stelle abfangen
- cmp num2_1, esc_code
- je shutdown
- cmp num2_1, "0"
- jl fehler
- cmp num2_1, "9"
- jg fehler
- sub al, 48
- mov num2_1, al
- ;2. Stelle
- mov ah,01h
- int 21h
- mov num2_2,al
- ;Falsche Eingabe 2. Stelle abfangen
- cmp num2_2, esc_code
- je shutdown
- cmp num2_2, "0"
- jl fehler
- cmp num2_2, "9"
- jg fehler
- sub al, 48
- mov num2_2,al
- ;Zahl zusammenfügen
- mov al,num2_1
- mul ten
- add al,num2_2
- mov charTwo, al
- mov ax, 1301h
- mov bx, colorTitle
- mov dh, 14 ;row
- mov dl, 34
- mov cx, 12
- mov bp, offset RESULT_LINE
- int 10h
- ret
- readSecondNum ENDP
- ;--------------------------------------------------------------------;
- ; ADDITION
- ;--------------------------------------------------------------------;
- addition:
- call readSecondNum
- ;Erste Zahl in AH und zweite dazu addieren
- mov al, num1_2
- add al, num2_2
- mov ah, 0
- aaa
- add ah, 48
- add al, 48
- add resultE, al
- add resultT, ah
- mov al, num1_1
- add al, resultT
- add al, num2_1
- mov ah, 0
- aaa
- add ah, 48
- add al, 48
- mov resultT, al
- add resultH, ah
- ;Resultmessage
- mov ah, 02h
- mov bh, 0
- mov dh, 16
- mov dl, 43
- int 10h
- mov ah, 2
- mov dl, resultH
- int 21h
- mov ah, 2
- mov dl, resultT
- int 21h
- mov ah, 2
- mov dl, resultE
- int 21h
- ;Calc finished
- jmp exit
- ;--------------------------------------------------------------------;
- ; MULTIPLICATION
- ;--------------------------------------------------------------------;
- multiplication:
- call readSecondNum ;Read second number
- ;Calc Ones
- mov al, num1_2
- mov bl, num2_2
- mul bl
- aam ;AH = Tens, AL, Ones
- add al, 48
- mov resultE, al ;AL = Ones
- mov cl, ah ;CL = Overflow for Tens
- ;Calc Tens
- xor ax, ax
- mov al, num1_2
- mov bl, num2_1
- mul bl
- aam ;AH = Hundrets, AL = Tens
- add cl, al ;CL = Tens
- mov ch, ah ;CH = Overflow for Hundrets
- xor ax, ax
- mov al, num1_1
- mov bl, num2_2
- mul bl
- aam ;AH, Hundrets, AL = Tens
- add al, cl ;CL = Tens
- add al, 48
- mov resultT, al
- add ch, ah ;CH = Hundrets
- ;Calc Hundrets & Thousands
- xor ax, ax
- mov al, num1_1
- mov bl, num2_1
- mul bl
- aam ;AL = Thousands, AH = Hundrets
- add ah, 48
- mov resultX, ah
- add ch, al ;CH = Hundrets
- add ch, 48
- mov resultH, ch
- ;Calc overflow
- cmp resultT, "9"
- jng tensNotGreater9
- sub resultT, 10
- add resultH, 1
- tensNotGreater9:
- cmp resultH, "9"
- jng hundertsNotGreater9
- sub resultH, 10
- add resultX, 1
- hundertsNotGreater9:
- ;Resultmessage
- mov ah, 02h
- mov bh, 0
- mov dh, 15
- mov dl, 42
- int 10h
- mov ah, 2
- mov dl, resultX
- int 21h
- mov ah, 2
- mov dl, resultH
- int 21h
- mov ah, 2
- mov dl, resultT
- int 21h
- mov ah, 2
- mov dl, resultE
- int 21h
- jmp exit
- ;--------------------------------------------------------------------;
- ; SUBTRACTION
- ;--------------------------------------------------------------------;
- subtraction:
- call readSecondNum
- ;Cursor für das Ergebnis ausrichten
- mov ah, 02h
- mov bh, 0
- mov dh, 15
- mov dl, 43
- int 10h
- ;prüfen ob num1_1 kleiner als num2_1, dann negativ
- mov al, num1_1
- cmp al, num2_1
- jl negativesErgebnis
- jg positivesErgebnis
- je zehnerZahlGleich
- zehnerZahlGleich:
- ;prüfen, ob num1_2 kleiner als num2_2, dann negativ
- mov al, num1_2
- cmp al, num2_2
- jl negativesErgebnis
- jg positivesErgebnis
- je zahlenGleich
- zahlenGleich:
- ;Ergebnisnachricht
- mov ah, 2
- mov dl, '0'
- int 21h
- mov ah, 2
- mov dl, '0'
- int 21h
- jmp exit
- positivesErgebnis:
- mov al, num1_2
- cmp al, num2_2
- jge groesser
- jl kleiner
- groesser:
- mov al, num1_2
- sub al, num2_2
- add al, 48
- mov bl, al
- xor al, al
- mov al, num1_1
- sub al, num2_1
- add al, 48
- ;Ergebnisnachricht
- mov ah, 2
- mov dl, al
- int 21h
- mov ah, 2
- mov dl, bl
- int 21h
- jmp exit
- kleiner:
- mov al, num1_2
- add al, 10
- sub al, num2_2
- add al, 48
- mov bl, al
- xor al, al
- mov al, num1_1
- sub al, 1
- sub al, num2_1
- add al, 48
- ;Ergebnisnachricht
- mov ah, 2
- mov dl, al
- int 21h
- mov ah, 2
- mov dl, bl
- int 21h
- jmp exit
- negativesErgebnis:
- mov al, num2_2
- cmp al, num1_2
- jge groesserNegativ
- jl kleinerNegativ
- groesserNegativ:
- mov al, num2_2
- sub al, num1_2
- add al, 48
- mov bl, al
- xor al, al
- mov al, num2_1
- sub al, num1_1
- add al, 48
- mov cl, al
- ;Ergebnisnachricht
- ;Vorzeichen ausgeben (-)
- mov ah, 02
- mov dl, 45
- int 21h
- mov ah, 2
- mov dl, cl
- int 21h
- mov ah, 2
- mov dl, bl
- int 21h
- jmp exit
- kleinerNegativ:
- mov al, num2_2
- add al, 10
- sub al, num1_2
- add al, 48
- mov bl, al
- xor al, al
- mov al, num2_1
- sub al, 1
- sub al, num1_1
- add al, 48
- mov cl, al
- ;Ergebnisnachricht
- ;Vorzeichen ausgeben (-)
- mov ah, 02
- mov dl, 45
- int 21h
- mov ah, 2
- mov dl, cl
- int 21h
- mov ah, 2
- mov dl, bl
- int 21h
- jmp exit
- ;--------------------------------------------------------------------;
- ; EXIT
- ;--------------------------------------------------------------------;
- exit:
- xor ax, ax
- mov ax, 1301h
- mov bx, colorRestart
- mov dh, 18 ;row
- mov dl, 29
- mov cx, 22
- mov bp, offset MSG_EXIT_RESTART
- int 10h
- loopm:
- mov ah, 01
- int 21h
- mov bl, al
- cmp al, 'j' ;Check if "j" is clicked -> restart
- je start
- cmp al, 'J' ;Check if "J" is clicked -> restart
- je start
- jmp shutdown ;Else shutdown
- shutdown:
- mov ax,3
- int 10h
- mov ax, 4c00h
- int 21h
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement