Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code segment
- assume cs:code, ss:stosik, ds:dane
- mov ax,dane
- mov ds,ax
- mov ax,stosik
- mov ss,ax
- mov sp,offset szczyt
- ;tak
- mov ah,09h ;usł. wysw string
- lea dx,tx1 ;wczytaj adres efektywny tx1
- int 21h
- mov ah,0Ah ;wczytanie lancucha
- lea dx,max ;il znaków do ah
- int 21h
- mov ah,09h
- lea dx,crlf
- int 21h
- ;zerowanie
- xor ax,ax
- xor bx,bx
- xor cx,cx
- xor dx,dx
- mov cl,len ;len faktyczna dlugosc
- testDlugosc:
- cmp len,0
- je pusty
- jmp testCzyLiczba
- pusty:
- mov ah,09h
- lea dx,err1
- int 21h
- mov ax,4c03h
- int 21h
- testCzyLiczba:
- mov dl,tab[bx]
- cmp dl,'0'
- jl blednaLiczba
- cmp dl,'9'
- jg blednaLiczba
- inc bx
- loop testCzyLiczba
- xor bx,bx
- mov cl,len
- jmp testZakres
- blednaLiczba:
- mov ah,09h
- lea dx,err2
- int 21h
- mov ax,4c02h
- int 21h
- testZakres:
- mov dx,10
- mov ax,suma
- mul dx
- jc przekroczono ;test overflow dla mnozenia
- mov dh,0
- mov dl,tab[bx]
- sub dx,'0'
- add ax,dx
- jc przekroczono ;test carry dla dodawania (add nie ustawia O)
- mov suma,ax
- inc bx
- loop testZakres
- jmp wypiszDec
- przekroczono:
- mov ah,09h
- lea dx,err3
- int 21h
- mov ax,4c03h
- int 21h
- ;jesli poprawny zakres, wypisz dziesietnie
- wypiszDec:
- mov ah,09h
- lea dx,txD ;text Decimal
- int 21h
- lea dx,tab
- int 21h
- lea dx,txB
- int 21h
- ;liczba binarnie
- ;ilosc znakow do przejscia binarnie
- ;maska 1
- mov ah,02h
- mov cx,16
- mov bx,suma
- wypiszBin:
- rol bx,1
- push bx
- and bx,1
- add bx,'0'
- mov dl,bl
- int 21h
- pop bx
- loop wypiszBin
- mov ah,09h
- lea dx,txH
- int 21h
- mov ah,02h
- ;liczba hex
- mov cx,4 ;4x 4znaki
- mov bx,suma
- wypiszHex:
- rol bx,4
- push bx
- and bx,15
- mov dl,hex[bx]
- int 21h
- pop bx
- loop wypiszHex
- ;koniec
- mov ax,4c00h
- int 21h
- code ends
- dane segment
- tx1 db 10,13,'Wpisz liczbe (0-65535): $'
- err1 db 10,13,'Podany ciag jest pusty!$'
- err2 db 10,13,'Podany ciag nie jest liczba!$'
- err3 db 10,13,'Podana liczba jest za duza!$'
- txD db 'Liczba dziesietnie: $'
- txB db 10,13,'Liczba binarnie: $'
- txH db 10,13,'Liczba szesnastkowo: $'
- hex db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
- crlf db 10,13,'$'
- max db 6
- len db ?
- tab db 7 dup('$')
- suma dw 0 ;liczba dziesietnie
- db '$'
- dane ends
- stosik segment
- dw 100h dup(0)
- szczyt Label word
- stosik ends
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement