Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .8086
- .MODEL TINY
- .data
- total dw 0
- nnnS dw 10
- TEN db 10
- temp dw 0
- inputcccS db 0Ah,0Dh, "cccS: ", "$"
- inputdddS db 0Ah,0Dh, "dddS: ", "$"
- inputArr db "Fill the array with 10 numbers from the range[0;65535]: ", "$"
- whiteSpace db 0Ah,0Dh,">>> ", "$"
- cout db 0Ah,0Dh,"<<< ", "$"
- ERRORMESSAGE db 0Dh,0Ah,"Incorrect number!","$"
- RESULTMESSAGE db 0Dh, 0Ah, "TOTAL: ", "$"
- endline db "", 0Ah,0Dh, "$"
- PARAMS LABEL BYTE
- MAXLEN DB 7
- ACTLEN DB ?
- STRING DB 7 DUP('$'),'$'
- .data?
- arrra dw 10 dup(?)
- cccS dw ?
- dddS dw ?
- .code
- org 100h
- MAIN:
- ;----------------------------------------------------------------
- ;--> INPUT array & CONVERT
- mov ah, 9h
- mov dx, offset inputArr
- int 21h
- mov bx, offset arrra
- mov cx, nnnS
- input_arr:
- mov temp, cx
- mov ah, 9h
- mov dx, offset whitespace
- int 21h
- mov ah, 0Ah
- mov dx, offset PARAMS
- int 21h
- xor dx, dx
- call convert
- cmp dx, 1
- JE ERROR
- mov [bx], ax
- add bx, 2
- mov cx, temp
- loop input_arr
- ;----------------------------------------------------------------
- mov ah, 9h
- mov dx, offset endline
- int 21h
- ;----------------------------------------------------------------
- ;--> INPUT cccS & dddS & CONVERT
- ;--> cccS
- mov ah, 9h
- mov dx, offset inputcccS
- int 21h
- mov ah, 0Ah
- mov dx, offset PARAMS
- int 21h
- xor dx, dx
- call convert
- cmp dx, 1
- JE ERROR
- mov cccS, ax
- ;--> dddS
- mov ah, 9h
- mov dx, offset inputdddS
- int 21h
- mov ah, 0Ah
- mov dx, offset PARAMS
- int 21h
- xor dx, dx
- call convert
- cmp dx, 1
- JE ERROR
- mov dddS, ax
- ;----------------------------------------------------------------
- ;----------------------------------------------------------------
- call show_arr
- JMP process
- ERROR:
- call errmsg
- JMP EXIT
- ;----------------------------------------------------------------
- ;--> COUNT TOTAL
- process:
- mov cx, nnnS
- mov bx, offset arrra
- count:
- mov ax, [bx]
- cmp ax, cccS
- JB BAD
- cmp ax, dddS
- JA BAD
- add total, 1
- BAD:
- add bx, 2
- loop count
- ;--> OUTPUT TOTAL
- OUTPUT:
- mov ah, 9h
- lea dx, RESULTMESSAGE
- int 21h
- mov ax, total
- mov cx, 10
- call Show_AX
- JMP EXIT
- EXIT: ret
- ;----------------------------------------------------------------
- ; ----> PROCEDURE: CONVERT STRING TO UNSIGNED INT
- convert:
- push bx
- push cx
- push di
- xor ax, ax ;обнуляется регистр
- lea di, STRING ;di - индексный регистр
- xor ch, ch ;обнуляется регистр
- mov cl, ACTLEN ;Число цифр в буфере
- xor bh, bh ;обнуляется регистр
- m1:
- mul TEN ;умножить ax на 10
- mov bl, [di] ;к произвдению добавить число
- cmp bl, 30h ;сравнение
- JL BADINPUTING ;если меньше '0'
- cmp bl, 39h ;сравнение
- JG BADINPUTING ;если больше '9'
- sub bl, 30h ;отнять 30h
- add ax, bx ;добачить число к сумме ax
- inc di ;инкремент di
- loop m1 ;повтор цикла
- JMP CONT
- BADINPUTING:
- mov dx, 1
- CONT:
- pop di
- pop cx
- pop bx
- ret
- ;----------------------------------------------------------------
- ; ----> PROCEDURE: OUTPUT ERRORMESSAGE
- errmsg:
- mov ah, 9h
- lea dx, ERRORMESSAGE
- int 21h
- ret
- ;----------------------------------------------------------------
- ; ----> PROCEDURE: CONVERT UNSIGNED INT TO STRING
- Show_AX:
- push ax
- push bx
- push cx
- push dx
- push di
- xor di, di ; di - кол. цифр в числе
- @@Conv:
- xor dx, dx
- div cx ; dl = num mod 10
- add dl, '0' ; перевод в символьный формат
- inc di
- push dx ; складываем в стэк
- or ax, ax
- jnz @@Conv
- ; выводим из стэка на экран
- @@Show:
- pop dx ; dl = очередной символ
- mov ah, 2 ; ah - функция вывода символа на экран
- int 21h
- dec di ; повторяем пока di<>0
- jnz @@Show
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- ;----------------------------------------------------------------
- show_arr:
- mov ah, 9h
- mov dx, offset endline
- int 21h
- mov bx, offset arrra
- mov cx, nnnS
- outputarr:
- mov temp, cx
- mov ah, 9h
- mov dx, offset whitespace
- int 21h
- mov ax, [bx]
- mov cx, 10
- call Show_AX
- add bx, 2
- mov cx, temp
- loop outputarr
- mov ah, 9h
- mov dx, offset endline
- int 21h
- ret
- ;----------------------------------------------------------------
- end MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement