Арифметические операции в языке программирования Assembler
Формулировка задачи:
здрастуйте
подскажите как сделать так что бы в результат выводило " значение с минусом" или "целое" или "дробей" а то ток с минусом кидает каждый раз
Листинг программы
- MODEL SMALL
- STACK 100h
- DATASEG
- Question DB 10,13,'Close program? - [Y/N]$'
- Set_X DB 13,10,'X = $'
- Result DB 13,10,'Y = $'
- error_ db "incorrect number$"
- buff db 6,7 Dup(?)
- CODESEG
- start:
- mov ax,@Data
- mov ds,ax ; ?????????? ??????? DS ????? ?????, ??? ??? ???????? ?? ??????? ?????
- mov dx,OFFSET Set_X ; ????????? ?? ????????????-?????????
- mov ah,09h ; ??????? DOS ?????? ???????
- int 21h
- ;************************************************************************************
- ;********* ?????????? ????? ? ?????????? ? ???????????? ???? ? ??????? ???????? ************
- ;********????????? ? ???????? AX*********
- ;************************************************************************************
- mov ah,0ah
- xor di,di
- mov dx,offset buff ; ?????? ??????
- int 21h ; ???????? ???????
- mov dl,0ah
- mov ah,02
- int 21h ; ???????? ??????? ???????
- ; ?????????? ????? ??????
- mov si,offset buff+2 ; ????? ?????? ??????? ???????
- cmp byte ptr [si],"-" ; ???? ?????? ?????? ?????
- jnz ii1
- mov di,1 ; ???????????? ??????
- inc si ; ? ?????????? ????
- ii1:
- xor ax,ax
- mov bx,10
- ii2:
- mov cl,[si] ; ????? ?????? ? ?????f
- cmp cl,0dh ; ??????????? ?? ??? ?? ????????
- jz endin
- ; ???? ?????? ?? ????????, ?? ??????????? ???? ?? ????????????
- cmp cl,'0' ; ???? ???????? ???????? ?????? <0
- jl er
- cmp cl,'9' ; ???? ???????? ???????? ?????? >9
- ja er
- sub cl,'0' ; ?????? ? ??????? ?????
- mul bx ; ???????????? ?? 10
- add ax,cx ; ??????? ?? ?????
- inc si ; ????????? ?? ????????? ??????
- jmp ii2 ; ??????????
- er: ; ???? ???? ???????, ?? ???????? ???????????? ??? ?? ? ????????
- mov dx, offset error_
- mov ah,09
- int 21h
- int 20h
- ; ??? ??????? ? ?????? ????????? ????? ??????????? ? ax
- endin:
- cmp di,1 ; ???? ???????????? ?????????, ??
- jnz ii3
- neg ax ; ????? ????? ?????????
- ii3:
- ;************************************************************************************
- ;**************** ?????????? ??????? ?????????? ? ????????????? ????? ********************
- ;
- mov bx,ax
- mov ax,4
- sub ax,bx
- test ax,ax
- jns div_5
- neg ax
- div_5:
- mov cx, 5
- div cx
- mov bx, ax
- mul bx
- mul bx
- jp write_neg
- add ax, 1
- mov cx, ax
- write_neg:
- neg ax
- add ax, 1
- mov cx,ax
- mov dx,OFFSET Result ; ?????? ??
- mov ah,09h ; ??????? DOS ?????? ????????????
- int 21h ; ??????? ?????????? ????????????
- xchg cx,ax
- ;************************************************************************************
- ;************* ??????? ??????? ???????????? ????? ? ??????? ? ?????? ?? ?? ????? ************
- ;************************************************************************************
- ; ??????????? ????? ?? ????
- test ax, ax
- jns oi1
- ; ???? ???? ???'????, ???????? ????? ? ???????? ???? ??????.
- mov cx, ax
- mov ah, 02h
- mov dl, '-'
- int 21h
- mov ax, cx
- neg ax
- ; ????????? ???? ?????? ??????? ? CX.
- oi1:
- xor cx, cx
- mov bx, 10 ; ?????? ??. 10 ??? ?????????? ? ?.?.
- oi2:
- xor dx,dx
- div bx
- ; ?????? ????? ?? ?????? ??. ? ??????? ???????? ??????? ?????.
- ; ??????? ???????? ?? ???????, ???? ????????? ?? ? ????.
- push dx
- inc cx
- ; ? ? ??????? ?????????? ?? ? ????, ?????????? ??? ????? ???????
- ; ????? ??????, ???? ?? ?????????? ????, ?? ???????, ?? ????
- ; ????? ???? ????.
- test ax, ax
- jnz oi2
- ; ????? ?????????? ?? ??????.
- mov ah, 02h
- oi3:
- pop dx
- ; ?????? ??????? ?????, ?????????? ?? ? ?????? ? ????????.
- add dl, '0'
- int 21h
- ; ????????? ????? ??????? ?????, ??????? ???? ??????????.
- loop oi3
- ;************************************************************************************
- ;************ ?????????? ??????? ???????????? ????? ? ??????? ? ?????? ?? ?? ????? ***********
- ;************************************************************************************
- mov dx,OFFSET Question
- mov ah,09h
- int 21h
- mov ah,01h
- int 21h
- cmp al,'y'
- jz closethatshit
- jmp start
- closethatshit:
- mov ah,04ch ; ??????? DOS ?????????? ????????
- int 21h ; ????????? ????????
- end start
Решение задачи: «Арифметические операции в языке программирования Assembler»
textual
Листинг программы
- endin:
- cmp di, 1
- jnz ii3
- neg ax
- ii3:
- ;************************************************************************************
- xor dx, dx
- mov bx, ax
- mov ax, 4
- sub ax, bx
- jns ii4
- mov dx, -1
- ii4:
- mov cx, 5
- idiv cx
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д