Here is my awful attempt at converting this:

int a=0;
if(a!=80)
{
a+=1;
}

to assembly (NASM):

push cx
mov cx, 80
loop:
je short endloop
mov al,0xDB
call kputchar
add word [d],1
cmp cx,[d]
endloop:
pop cx

...

d dw 0

I am not very good at ASM, so any help would be much appreciated. TIA

Your original "if" statement mutated into a loop there... let's look at the "if" by itself first.

A basic assembly "if" block might look like this:

cmp a, 80
  jne notequal
  ; a == 80, do something here
  jmp done
notequal:
  ; a != 80, do something else here
done:
  ; program continues...

In your case, it can be a little simpler:

cmp a, 80
  je equal
  inc a  ; only increment when a != 80
equal:
  ; program continues...

You could write your loop using similar code, but the 8086 instruction set includes a LOOP instruction.

A basic assembly "for" loop block might look like this, using CX as your loop counter:

push cx
  mov cx, 80
label:
  ; do something here
  loop label
  pop cx

Note that LOOP counts down to zero.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.