All posts categorized amd64

x86-64 TUTORIAL: HELLO WORLD!

Below is a program that prints "Hello World!" on screen followed by a newline character. In the data section we first store the string "Hello World!", followed by the newline character which has an ASCII value of 10 and the NULL character or the value 0. The NULL character is used here because of the way we calculate the string length. There are other ways to calculate the string length as well, by using NASM’s directives like equ, but we shall use that in another sample program.

Read More
Posted on by Vikas N. Kumar.

x86-64 TUTORIAL: INPUT OUTPUT FUNCTIONS

Here are some print functions for strings, integers and newline characters. There is also a function for reading an integer. All the code is in NASM’s syntax. The macros prologue and epilogue, are used to save space and avoid repetitiveness.

NOTE: Remember that the registers RBP, RBX and R12-R15 need to be saved across function calls.

Read More
Posted on by Vikas N. Kumar.

x86-64 TUTORIAL: MULTIPLICATION & DIVISION

In the Hello World sample program we had used the instructions REPNZ and SCASB to calculate the length of the string being printed at runtime. In this program we use NASM’s equ directive to calculate the length during assembly time as opposed to at runtime. The variable promptlen gives an example.

Read More
Posted on by Vikas N. Kumar.

x86-64 TUTORIAL: FIND PRIME NUMBERS

Below is a code snippet that prints a list of prime numbers, one on each line, based on a limit entered by the user. It uses both while loops and conditional branch if - else statements. We shall convert this to an assembly program to demonstrate implementation of these control flow structures in x86-64 assembly.

Read More
Posted on by Vikas N. Kumar.

x86-64 TUTORIAL: BIT SHIFTING OPERATIONS

Logical shifts are operations in which the bits of a register or memory location are moved to the right or left by a certain number or a value in the CL register. They are also a very quick way to multiply or divide by 2 or powers of 2 as it involves just a shift of bits. There are 4 shift bit instructions, 4 rotate bit instructions and 2 double precision shift bit instructions for general purpose registers.

Read More
Posted on by Vikas N. Kumar.

Pages: Previous  |  1  |  2  |  3  |  4  |  Next
SUPPORT THIS SITE
Donate DOGECOIN to DBevjMg3fd8C5oxZbV8sFpAffo6Tas1s8Q. DBevjMg3fd8C5oxZbV8sFpAffo6Tas1s8Q Donate BITCOIN to 19hrWWw1dPvBE1wVPfCnH8LqnUwsT3NsHW. 19hrWWw1dPvBE1wVPfCnH8LqnUwsT3NsHW
As an Amazon Associate I earn from qualifying purchases.