Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- model small
- dataseg
- ERROR DB 'Overflow', 0Dh, 0Ah, '$'
- INPUT db 'Input your integer array:', 0Dh, 0Ah, '$'
- INBUF db 252, ?, 254 dup(?)
- ARR dw 126 dup(0h)
- codeseg
- startupcode
- mov AX, @DATA ; Setting start of dataseg
- mov DS, AX ; to registers DS and ES
- mov ES, AX
- xor AX, AX
- ; Output INPUT message
- lea DX, INPUT
- mov AH, 009h
- int 21h
- ; Input buffer
- lea DX, INBUF ; Move address of inbuf to DX
- mov AH, 0Ah ; Set num of input programm to AH
- int 21h ; Call input
- xor CX, CX ; CX = 0
- mov CL, INBUF+1 ; CL = size of inbuf
- mov AL, ' ' ; its for jumping spaces by scasb
- cld ; Set diraction flag (DF) to 0 (forward)
- lea DI, INBUF+2 ; Set adress of input string to DI
- xor SI, SI ; Set SI to zero
- bufprs: repe scasb ; Jump all spaces
- inc CX
- jcxz exit ; if it's end of buf - end ' +2'
- xor AH, AH ; Set AH to zero
- dec DI ; After jumping we can stay after sign or digit
- mov CH, [DI] ; Move symbol to CH
- cmp CH, '-' ;
- jne plus ; if CH = '-', then
- mov AH, 001h ; then set AH flag for negative value
- dec CX
- inc DI ; and jump this symbol
- jmp signe ;
- plus: cmp CH, '+' ; if there '+'
- jne signe ;
- inc DI ; jump this symbol
- dec CX
- signe: xor BX, BX ; BX = 0. ' +2'
- iprs: mov CH, [DI] ; Move symbol to CH (again, if there was sign symb)
- cmp CH, '0' ;
- jl cont ; if CH isn't digit
- cmp CH, '9' ; move BX to array (in the 'cont')
- jnle cont ;
- mov DX, BX ; DX = BX
- sal BX, 3 ; BX = 8*BX
- sal DX, 1 ; DX = 2*BX
- add BX, DX ; BX = 10*BX
- sub CH, '0' ; Get digit from CH
- xor DX, DX ; Dx = 0
- mov DL, CH ; DX = CH (it's inpossible to do add BX, CH)
- add BX, DX ; BX = 10*BX + CH (CH here its DX)
- inc DI ; Move DI forward
- xor CH, CH ; Set CH to zero
- loop iprs
- cont: cmp AH, 1 ; if there negative flag
- jl setv ;
- neg BX ; set negative BX
- setv: mov ARR[SI], BX ; move BX to array
- add SI, 2 ; incerment index of 'arr' array
- xor CH, CH ; Clear CH
- inc CL ; return extra decremented 1
- loop bufprs
- exit: mov AX, 04Ch
- int 21h
- end
Add Comment
Please, Sign In to add comment