Skip to content
Advertisement

NASM division using variables instead of actual values

I’m learning some basic arithmetic using NASM on Linux. I need to divide two numbers using variables NUMBER1 and NUMBER2. My code works if I type in actual value instead of variables. For example if I type in ‘6’ instead of NUMBER2 and ‘2’ instead of NUMBER1, the program does division and gives me answer of 3. Running code with variables gives FLOATING EXCEPTION (CORE DUMPED). could please explain how correctly use variables in this code? While debugging, I see that the problem is in DIV line. Thank you !

JavaScript

Advertisement

Answer

Because given example is supposed to process ASCII codes for numbers, not numbers themselves. If you enter 6 instead of '6', 6 - '0' evaluates to 65494 (not 6). If you try to divide further by 2, processor is unable to store quotient in lower half of ax register.

If you do not intend to output result to console and only try to learn how division with one byte integer works using assembler, pick your favourite debugger, place breakpoint after division operation and enjoy your result.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement