Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FASM.
- boot.ASM:
- org 0x7C00
- start:
- cli
- xor ax,ax
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,0x7C00
- sti
- mov ax,2
- int 0x10
- mov dx,0
- call set_cursor_pos
- mov bp,msg
- mov cx,10
- call print_mes
- add dh,1
- call set_cursor_pos
- mov bp,con
- mov cx,14
- call print_mes
- cont:
- mov ah,0x10
- int 0x16
- cmp al,0xD
- jz kernel
- jmp cont
- kernel:
- mov ax,0
- mov es,ax
- mov bx,0x7E00 ;dl'a chego????????!!?! mozhno zhe shto ugodno postavit'
- mov ch,0
- mov cl,2
- mov dh,0
- mov dl,0x80
- mov al,2
- mov ah,2
- int 0x13
- jmp 0x7E00
- print_mes:
- mov bl,3
- mov ax,0x1301
- int 0x10
- ret
- set_cursor_pos:
- mov ah,2
- xor bh,bh
- int 0x10
- ret
- ;-------------------------------------------------
- msg db 'loading...',0
- con db 'press Enter...',0
- finish: times 0x1FE-finish+start db 0
- db 0x55,0xAA
- prog.ASM:
- org 0x7E00
- start:
- mov ax,2
- int 0x10
- mov dx,0
- call set_cursor_pos
- mov di,opr
- call print
- call input_sdec_word
- call print_endl
- mov bx,ax
- mov di,opr
- call print
- call input_sdec_word
- call print_endl
- push dx
- mov dx,bx
- mov bx,ax
- mov ax,dx
- pop dx
- mov di,diya
- call print
- call operac
- call print_endl
- mov di,vihodfraz
- call print
- call print_word_sdec
- call print_endl
- mov di,pak
- call print
- mov ah,0x00
- int 0x16
- call print_endl
- jmp start
- ;-------------------------------------------------
- print:
- push ax
- push bx
- mov ah,0x0E
- mov bh,0x00
- putch_lp:
- mov al,byte[di]
- inc di
- test al,al
- jz print_exit
- inc dl
- int 0x10
- jmp putch_lp
- print_exit:
- pop bx
- pop ax
- ret
- print_endl:
- push di
- mov di,endline
- call print
- pop di
- mov dl,0
- inc dh
- call set_cursor_pos
- ret
- ;-------------------------------------------------
- word_to_udec:
- push cx
- push dx
- push bx
- xor cx,cx
- mov bx,10
- wu_lup1:
- xor dx,dx
- div bx
- add dx,'0'
- push dx
- inc cx
- test ax,ax
- jnz wu_lup1
- wu_lup2:
- pop dx
- mov [di],dl
- inc di
- loop wu_lup2
- pop bx
- pop dx
- pop cx
- ret
- print_word_sdec:
- push di
- mov di,buffer
- push di
- call word_to_sdec
- mov byte[di],0
- pop di
- call print
- pop di
- ret
- word_to_sdec:
- push ax
- test ax,ax
- jns wtsd_nosign
- mov byte[di],'-'
- inc di
- neg ax
- wtsd_nosign:
- call word_to_udec
- pop ax
- ret
- ;-------------------------------------------------
- input:
- push ax
- push bx
- push cx
- xor si,si
- input_jmp:
- mov ah,0x10
- int 0x16
- cmp ah,0xE
- jz delete_symbol
- cmp al,0xD
- jz input_end
- mov [inp_buf+si],al
- inc si
- mov ah,9
- mov bl,5 ;atribut
- mov cx,1
- int 0x10
- add dl,1
- call set_cursor_pos
- jmp input_jmp
- delete_symbol:
- cmp dl,0
- jz input
- sub dl,1
- call set_cursor_pos
- mov al,0x20 ;probel
- mov [inp_buf+si],al
- dec si
- mov ah,9
- mov bl,7
- mov cx,1
- int 0x10
- jmp input_jmp
- input_end:
- pop cx
- pop bx
- pop ax
- ret
- ;-------------------------------------------------
- input_sdec_word:
- push bx
- push cx
- call input
- mov cx,si
- mov di,inp_buf
- call to_sdec_word
- isw_exit:
- pop cx
- pop bx
- ret
- to_sdec_word:
- push bx
- push dx
- mov bl,byte[di]
- cmp bl,'-'
- jnz tsw_unsign
- inc di
- dec cx
- tsw_unsign:
- call to_udec_word
- jc tsw_error
- mov di,inp_buf
- mov bl,byte[di]
- cmp bl,'-'
- jz tsw_minus
- cmp ax,32767
- ja tsw_error
- jmp tsw_exit
- tsw_minus:
- cmp ax,32768
- ja tsw_error
- neg ax
- jmp tsw_exit
- tsw_error:
- call print_endl
- mov di,errorline
- call print
- xor ax,ax
- tsw_exit:
- pop dx
- pop bx
- ret
- to_udec_word:
- push cx
- push dx
- push bx
- push si
- push di
- mov si,10
- xor ax,ax
- xor bx,bx
- xor dx,dx
- tuw_lp:
- mov bl,[di]
- inc di
- cmp bl,'0'
- jl tuw_error
- cmp bl,'9'
- jg tuw_error
- sub bl,'0'
- mul si
- jc tuw_error
- add ax,bx
- loop tuw_lp
- jmp tuw_exit
- tuw_error:
- call print_endl
- mov di,errorline
- call print
- xor ax,ax
- tuw_exit:
- pop di
- pop si
- pop bx
- pop dx
- pop cx
- ret
- ;-------------------------------------------------
- operac:
- push di
- call input
- push dx
- mov di,inp_buf
- mov dl,byte[di]
- cmp dl,'+'
- jz op_plus
- cmp dl,'-'
- jz op_minus
- cmp dl,'*'
- jz op_umn
- cmp dl,'/'
- jz op_del
- jmp operac_end
- op_plus:
- add ax,bx
- jmp operac_end
- op_minus:
- sub ax,bx
- jmp operac_end
- op_umn:
- imul bx
- jmp operac_end
- op_del:
- idiv bx
- operac_end:
- pop dx
- pop di
- ret
- ;-------------------------------------------------
- set_cursor_pos:
- push bx
- push ax
- mov ah,2
- xor bh,bh
- int 0x10
- pop ax
- pop bx
- ret
- ;-------------------------------------------------
- inp_buf rb 8
- buffer rb 8
- errorline db 'error...',0
- pak db 'press any key...',0
- opr db 'operand: ',0
- diya db 'operation: ',0
- vihodfraz db 'chislo: ',0
- endline db 13,10,0
- sbor.ASM:
- macro align value { db value-1 - ($ + value-1) mod (value) dup 0 }
- HEADS = 1
- SPT = 2
- Begin:
- file "boot.bin",512
- file "prog.bin"
- align 512
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement