B
B
Bbb1232018-04-17 08:47:10
assembler
Bbb123, 2018-04-17 08:47:10

How to implement such a loop in assembler: FOR I:=1 TO 9 DO IF X[I] < 0 THEN AL:=AL+1?

Here's what I have, maybe someone will tell you what's wrong or what to add, something is missing (it seems to me), and what I can't understand (don't judge strictly).
MOV SI,1
MOV CX,9
M1: MOV AL,ARRAY_X[SI]
CMP AL,0
JS M2
INC SI
M2: inc AL
LOOP M1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2018-04-17
@Bbb123

1. Do you place an array element in AL and increment it?
2. In this case, you can simply sum the sign bits in the elements. Something like this:

mov al, 0
mov si, 1
mov cx, 9
m1: 
mov bl, ARRAY_X[si]
shr bl, 7
add al, bl 
inc si
loop m1

F
forspamonly2, 2018-04-17
@forspamonly2

MOVQ mm0, [ARRAY_X+1]
PMOVMSKB eax, mm0
POPCNT eax, eax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question