Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *= $0 ; $00 = Zeropage, $10 = Stack
- .START Main
- Zahl1 .DB $00
- *= * + 2 ; byte Zahl1[2]
- Zahl2 .DB $00
- *= * + 2 ; byte Zahl2[2]
- Real1 .DB $00
- ; byte Real1
- Real2 .DB $00
- ; byte Real2
- InputMsg .BYTE "Eingabe: ", $0
- *= $200
- io_area = $e000
- io_cls = io_area + 0 ; io_cls()
- io_putc = io_area + 1 ; io_putc()
- io_putr = io_area + 2 ; io_putr()
- io_puth = io_area + 3 ; io_puth()
- io_getc = io_area + 4 ; io_getc()
- mul_a = $2006
- mul_b = $2007
- mul_el = $2000
- mul_eh = $2001
- mul_ex = $2002
- Main:
- ; main()
- LDY #$0
- ; Y = 0x1
- .GetKey
- ; while(Y < 2)
- LDA io_getc
- BEQ .GetKey
- ; if !io_getc() goto GetKey
- TAX
- TYA
- PHA
- TXA
- ; [Push] Y by X=A -> A=Y -> [Push] A -> A=X
- PHA
- PHA ; [Push] A,A
- JSR IsNumber
- PLA
- BEQ .GetKey
- ; if !IsNumber(A) goto GetKey else
- PLA
- STA io_putc
- ; [Pop] A, io_putc()
- TAX
- PLA
- TAY
- TXA
- ; [Pop] Y by X=A -> [Pop] A -> Y = A -> A = X
- SEC
- SBC #$30
- ; A = A - 0x30
- STA Zahl1, Y
- ; Zahl1[Y] = A
- TYA
- CMP #$2
- BEQ .GetKeyEnd
- INY
- JMP .GetKey
- ; if Y == 2 goto GetKeyEnd else
- ; Y++
- ; goto GetKey
- .GetKeyEnd
- LDY #$0
- LDA Zahl1, Y
- STA mul_a
- LDA #$64
- STA mul_b
- JSR Mul
- LDA mul_el
- STA Real1
- ; Real1 = Mul(Zahl1[0], 0x64)
- LDY #$1
- LDA Zahl1, Y
- STA mul_a
- LDA #$a
- STA mul_b
- JSR Mul
- LDA mul_el
- CLC
- ADC Real1
- STA Real1
- ; Real1 = Real1 + Mul(Zahl1[1], 0xA)
- LDY #$2
- LDA Zahl1, Y
- CLC
- ADC Real1
- STA Real1
- ; Real1 = Real1 + Zahl1[2]
- ; io_puth(Real1)
- LDY $0
- ; Y = 0x0
- .GetKey2
- ; while(Y < 2)
- LDA io_getc
- BEQ .GetKey2
- ; if !io_getc() goto GetKey
- TAX
- TYA
- PHA
- TXA
- ; [Push] Y by X=A -> A=Y -> [Push] A -> A=X
- PHA
- PHA ; [Push] A,A
- JSR IsNumber
- PLA
- BEQ .GetKey2
- ; if !IsNumber(A) goto GetKey else
- PLA
- STA io_putc
- ; [Pop] A, io_putc()
- TAX
- PLA
- TAY
- TXA
- ; [Pop] Y by X=A -> [Pop] A -> Y = A -> A = X
- SEC
- SBC #$30
- ; A = A - 0x30
- STA Zahl2, Y
- ; Zahl2[Y] = A
- TYA
- CMP #$2
- BEQ .GetKeyEnd2
- INY
- JMP .GetKey2
- ; if Y == 2 goto GetKeyEnd else
- ; Y++
- ; goto GetKey
- .GetKeyEnd2
- LDY #$0
- LDA Zahl2, Y
- STA mul_a
- LDA #$64
- STA mul_b
- JSR Mul
- LDA mul_el
- STA Real2
- ; Real2 = Mul(Zahl2[0], 0x64)
- LDY #$1
- LDA Zahl2, Y
- STA mul_a
- LDA #$a
- STA mul_b
- JSR Mul
- LDA mul_el
- CLC
- ADC Real2
- STA Real2
- ; Real2 = Real2 + Mul(Zahl2[1], 0xA)
- LDY #$2
- LDA Zahl2, Y
- CLC
- ADC Real2
- STA Real2
- ; Real2 = Real2 + Zahl2[2]
- LDA Real2
- STA io_puth
- ; io_puth(Real2)
- BRK
- ; BRK()
- ; End of Programm, HALT
- DisplayS:
- ; Display() ---> Later
- RTS
- IsNumber:
- ; IsNumber()
- PLA
- TAX
- PLA
- TAY
- ; X, Y = [Top], [Top]
- PLA
- ; A = [Top]
- CMP #$30
- BCC .IsNumber_False
- CMP #$3a
- BCS .IsNumber_False
- ; if A < 0x30 && A >= 0x3a goto IsNumber_False
- LDA #$1
- PHA
- JMP .IsNumber_Return
- ; return 0x1;
- .IsNumber_False
- LDA #$0
- PHA
- ; return 0x0;
- .IsNumber_Return
- TYA
- PHA
- TXA
- PHA
- RTS
- Add_16:
- ; Add_16()
- CLC
- LDA $2000
- ADC $2002
- STA $2000
- ; *(0x2000) = *(0x2000) + *(0x2002)
- LDA $2001
- ADC $2003
- STA $2001
- RTS
- ; return *(0x2001) = *(0x2001) + *(0x2003)
- Mul:
- ; Mul()
- LDY #$00
- STY $2000
- STY $2001
- ; *(0x2000), *(0x2001) = 0x0
- LDA $2007
- BEQ .Mul_Exit
- STY $2003
- .Mul_Init_Multiplicant
- LDY $2006
- STY $2002
- .Mul_Next_Digit
- LSR
- TAY
- BCC .Mul_Skip_Add
- ; if *(0x2007) << 1 < [Pop] A goto SKIP_ADD
- .Mul_Add
- JSR Add_16
- ; ADD_16()
- .Mul_Skip_Add
- .Mul_Shift
- ; SkipAdd() = Shift()
- ASL $2002
- ROL $2003
- TYA
- BNE .Mul_Next_Digit
- .Mul_Exit
- RTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement