Click to See Complete Forum and Search --> : help me with this problem:(


king-gideon
April 3rd, 2009, 03:21 AM
i need to replace all the negative elements in an array with zero.i tried writing this and i got stuck:( i urgently need help
.model small
.stack 100h
.data
DEC_SIZE EQU 5
RES DB DEC_SIZE DUP('0')
TEMP DW ?
array dw 1,2,3,-5,6,-6
.code
.startup
mov cx,6
mov bx,array
cmp [bx],0
jnb Mark
mov [bx],0


Mark:
add bx,2
cmp [bx],0
jnb 0mark
cmp[bx],0
0mark: LOOP Mark

mov bx,array
MOV AX,[bx]
MOV CX,10
MOV RES+DEC_SIZE,'$'
MOV BX,OFFSET RES+DEC_SIZE
CYCLE: DEC BX
XOR DX,DX
DIV CX
ADD DL,'0'
MOV [BX],DL
CMP BX,OFFSET RES
JNE CYCLE
MOV AH,09
LEA DX,RES
INT 21H
mov cx,6

ft: mov cx,TEMP
MOV AX,[bx]
MOV CX,10
MOV RES+DEC_SIZE,'$'
MOV BX,OFFSET RES+DEC_SIZE
CYCLE: DEC BX
XOR DX,DX
DIV CX
ADD DL,'0'
MOV [BX],DL
CMP BX,OFFSET RES
JNE CYCLE
MOV AH,09
LEA DX,RES
INT 21H
mov cx,temp
loop ft

ret
End Startup

rxbagain
April 3rd, 2009, 09:55 AM
You should use JNL instead of JNB. JNB is used for unsigned numbers so there's nothing less than 0 :D.

Another option is to check the sign bit (bit 7 for byte; bit 15 for word; bit 31 for dword) but comparing the value to 0 is easier to maintain.

king-gideon
April 3rd, 2009, 11:11 AM
i also have a problem of printing out the new array.can u help me pls?

king-gideon
April 3rd, 2009, 11:19 AM
and the progam is not working:(

rxbagain
April 3rd, 2009, 12:03 PM
Hi gideon,

Here's the modified code

.model small
.stack 100h
.data
DEC_SIZE EQU 5
RES DB DEC_SIZE DUP('0')
TEMP DW ?
array dw 1,2,3,-5,6,-6
.code
.startup

; VALIDATION PROCESS
mov cx, 6 ; put the count item count in CX
lea bx, array ; we get the address of the array
process_word:
cmp word ptr [bx], 0 ; compare the value to 0
jnl process_next ; if NOT less than, skip the intruction below (mov)
mov word ptr [bx], 0 ; we replace the value with 0
process_next:
add bx, 2 ; move to the next element
LOOP process_word ; loop until CX = 0


; PRINTING PROCESS
mov cx, 6 ; put the count item count in CX
lea bx, array ; get the address of the array
PRINT_NUMBER:
push bx ; we preserve bx and cx to the stack since
push cx ; they will be modified during the printing

MOV AX,[bx] ; gideon's original code block
MOV CX,10
MOV RES+DEC_SIZE,'$'
MOV BX,OFFSET RES+DEC_SIZE
CYCLE: DEC BX
XOR DX,DX
DIV CX
ADD DL,'0'
MOV [BX],DL
CMP BX,OFFSET RES
JNE CYCLE
MOV AH,09
LEA DX,RES
INT 21H

mov dl, ' ' ; we add space to separate the results
mov ah, 2
int 21h
pop cx ; we now get the values of bx and cx
pop bx ; from the stack
add bx, 2 ; move to the next element in the array
loop PRINT_NUMBER ; loop PRINT_NUMBER while CX > 0

.exit

End

king-gideon
April 3rd, 2009, 12:32 PM
thanks very much!!!!!!!!!!!!!! its working perfectly welllllllllllllllllll