Assembly || How To Obtain & Display Integer Data

Print Friendly, PDF & Email

Displaying text to the screen was discussed in the previous article, and this page will be more of the same. Utilizing the printf and scanf functions which are available in C, this page will demonstrate how to obtain and display integer data; and more importantly, demonstrate how to store a 64-bit integer into an assembly program.

==== Obtain & Display Integer Data ====

Here is our driver.c file, which starts things off.

The “driver” file really only has one task, and that is simply to call the assembly function named ‘DisplayNum()’ as noted on line 38. This is a routine that is present among all the code on this site. Click here for an explanation on why a “driver” is used.

And here is the assembly file.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The text declarations highlighted under the segment .data section are important, particularly the variable named “unsignedLongIntegerInput.” That variable is used to obtain data from the user, as noted on line 74-77. Note, that this same variable is also used to display the integer data back to the user, which is also displayed on lines 86-89.

The rest of the code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

After you assemble the above code (see below), you should get this as your output:

Welcome to My Programming Notes' Assembly Program.

Control will now be passed to the Assembly file...

--------------------------------------------
Please enter a number: 1858
The number you just entered is: 1858
--------------------------------------------

Control has now been passed back from the Assembly file to the C file!

The return code is: 0

BYE!

==== ASSEMBLING THE CODE ====

This can be achieved by simply opening the teminal, and doing a copy/paste of the commands listed on the ‘driver.c’ file, lines 15 thru 18. Make sure to compile them in order for the sake of continuity.


Be advised, that the commands to assemble the code is designed to run in 64-bit mode. If you are not running a 64-bit machine, the commands will most likely fail to assemble.

If you are running a Windows computer and would like to assemble the code, look here or here for information.

You will need to change the 64-bit registers to 32-bit registers in the “displayNum.asm” file, aswell as removing lines 41-55 and lines 106-120 respectively in order to run the program successfully.

Was this article helpful?
👍 YesNo

Leave a Reply