0

I have problem with my code. this code in c++ i have to write in assembly. i try to write but it doesnt work

for (i=1; i<11; i++)
if(i%2 == 0)
sum = sum +i

mov cl, 02d
mov ax, 0d
mov bh, 0d
check:
inc al
mov dl, al
div cl
cmp ah, 0d
je sum
cmp ax, 11d
jne check


sum:
add bh, al
jmp check

2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by kikiritce
1

The previous contents of the accumulator AX is destroyed on each
execution of DIVide. Hence your are dividing your divisor by your
previous remainder and quotient in AX. That seems to me a bug.

An 8-bit divisor will divide against a 16-bit Implicit Dividend in AX,
after the division AH will contain the remainder and AL the quotient.

MOV AX, 1
MOV CL, 2
myloop:
PUSH AX
DIV CL ; Divide 8-bit CL by 16-bit dividend in AX, AH=Remainder AL=Quotient
CMP AH, 0 ; Is remainder 0? i%2=0, percentage is modulus operator in C/C++
JZ Sum
POP AX ; Restore contents of AX, 1 on first loop
INC AX
CMP AX, 11
JB myloop
Sum:
; AL will contain quotient
ADD [MySum], AL
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.