1

Im trying to work with nasm from C and just having a hard time with the basics of nasm. Im trying to convert a simple while loop like this

while(j < k)
{k = k + 1;
 j = j + 2;
 count = count + 1;
}

I know that it will look something like

Loopee:

????
add dword [k], 1
add dword [j], 2
add dword [count], 1

but I'm not sure how to structure the while loop where it only loops until j is no longer less than k.

Paul R
  • 208,748
  • 37
  • 389
  • 560
MrPorba
  • 59
  • 1
  • 2
  • 6
  • Have you seen this link? [assembly to compare two numbers](http://stackoverflow.com/questions/1123396/assembly-to-compare-two-numbers) – Tamerz Apr 27 '15 at 20:56
  • 1
    Write it in C first, then use your compiler to generate asm (e.g. `gcc -S ...`), then use the generated asm as a template for your own code. – Paul R Apr 27 '15 at 21:04
  • 1
    In order to write assembly code, you must first understand the processor instruction set. Here's a **[link](http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-manual-325462.html)** to the documentation. It's only 3400 pages, so you should be able to finish reading it by tomorrow :) – user3386109 Apr 27 '15 at 21:17

1 Answers1

2

A while loop is just like an IF statement, except that at the bottom of the body you unconditionally jump back to the IF (the start of the loop).

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101