Skip to content

Assembly Language: Pseudo-Instructions

Before trying to get our hands on Pseudo-Instructions, lets first do a recap of last two post. After that we’ll try to look into more mnemonics before actually moving on to Assembly Language Programming. This will be a wild run so keep it tight, keep it together. :P

Recap

Till now we talked about x86 family of processors, their 16-bit registers and 32-bit registers, EAX, EBX, ECX and so on. Mode of operations in above processors i.e real mode and protected mode and little bit about the differences between them and then very little touch on Interrupts.

Then we moved on assembly language, how its better then machine language and basic instructions in assembly language i.e MOV, ADD, SUB, INC and DEC and how to comment in the ASM code. If you know exactly what i’m talking about then we are good to move forward if not then visit my previous post regarding assembly language.

So if you are still here then i can assume you know what i was talking about.
In that case lets move forward…

In this post we’ll learn about Pseudo-Instructions. This post will closely follow NASM and might not work with other assemblers so take it all with a pinch of salt.

Pseudo-Instructions

Pseudo-instructions are not x86 instructions directly rather they are part of the NASM assembler (though are very common in other assemblers too.). These are used to declare initialized and uninitialized data and few other things. Lets look over them in brief :

Declaring Initialized Data

DB, DW, DD, DQ, DT, DDQ, DO are used to declare initialized data in the output file. D stands for data and rest are defined in following table:

general format for this is –

few ways to call these :

Note : In assembly language double quotes and single quotes are same. so ‘A’ is same as “A”.

Till now we only declare single initialized byte or word or other now lets see how to initialize multiple at once. just like arrays in C/C++.

Note : To define a null terminated string in assembly it must contain 0 at the end.

Declaring Uninitialized Data

RESB, RESW, RESD, RESQ, REST, RESDQ are just like reinitialized data declaration just it only reserves the bytes and have only one operand that is no. of byte, word, double word etc to reserve. And you have guessed it right RES stands for reserve and fallowing latter represents byte, word etc same as above table. E.g.

Including external binary file
INCBIN pseudo-instruction is used to include a binary file into the output file. this can be handy to include other binaries into the code like graphics. However its highly recommended not to use large pieces of binary. INCBIN can work with 1 to 3 operands where first one is the name of the binary file, second is the starting point and third being the max number of bytes to include. E.g.

Defining Constants

To define constants just like in C/C++ we use EQU keyword or instruction. So just like C/C++ we cannot alter the value later during the execution. EQU actually defines a label name to the value and this definition is absolute. E.g.

The above instructions will create a message with ‘hello, world’ and msglen 12, msglen cannot be altered. Remember double quotes and single quotes both are same in assembly :).

Repeating Instructions or Data

The final pseudo-instruction for this tutorial is TIMES. As the heading suggest its used to do declare or reserve multiple times or repeatedly. you can treat it as while loop in C/C++. time is very versatile instruction it can iterate constant number of times or till a condition fulfills. E.g.

In above statement db 0 will run 64 times, but as i said times is much more versatile you can pass other instructions as well. E.g.

However you cannot pass macro (worry not will be covered later!) in TIMES as macros process well before the assembler executes TIMES.

NOTE : if your using MASM then TIMES is not there use DUP (duplicate) instead.

Well this is enough for this time will learn about expressions and critical expressions.
As always thank you for reading.
cheers!

Published inAssembly Language

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *