I.1. The Elements of The IA32 Assembly Language: X and X
I.1. The Elements of The IA32 Assembly Language: X and X
I.1. The Elements of The IA32 Assembly Language: X and X
Converting numbers
between numbering bases 2, 10, 16. Representation of integer numbers in the
computer’s memory. Signed and unsigned instructions.
The IA-32 computing architecture is the microprocessor (CPU) architecture introduced by the
Intel Corporation in 1985 for their 80386 microprocessor. It is an abstract model of a
microprocessor specifying the microprocessor’s elements, structure and instruction set. The IA-
32 is a 32-bit computing architecture (basically meaning that its main elements have 32 bits in
size) and it is based on the previous Intel 8086 computing architecture.
An algorithm can be described using the natural language (e.g. romanian language, English
language etc.) or it can be described in a programming language (e.g. C, Java, python, php etc.).
When an algorithm is specified in a programming language, we refer to this algorithm as a
program. In a similar way, a program contains: a) a set of data/entities and b) a set of
operations/instructions.
Throughout the semester we will study the IA-32 assembly language. We will first describe the
data part of the assembly language and later the operational part (instructions). All data used in
an IA-32 assembly program is essentially numerical (integer numbers) and can have 3 basic
types:
byte – that data is represented on 8 bits
word – that data is represented on 16 bits
doubleword – that data is represented on 32 bits
In the IA-32 assembly language we have data that does not changes its value throughout the
execution of the program (i.e. constant data or constants) and data that does change its value
throughout the execution of the program (i.e. variable data or variables).
I.1.1 Constants
We have 3 types of constants in the IA-32 assembly language:
numbers (natural or integer):
o written in base 2; ex.: 101b, 11100b
o written in base 16; ex.: 34ABh, 0ABCDh
o written in base 10; ex.: 20, -114
character; ex.: ‘a’, ‘B’, ‘c’ ..
string (sequence of characters); ex.: ‘abcd’, “test” …
I.1.2 Variables
The IA-32 assembly language has 2 kinds of variables: pre-defined variables and user-defined
variables. A variable has a name, a data type (byte, word or doubleword), a current value and a
memory location (where the variable is stored).
User-defined variables:
For these variables, the programmer has to define the name, data type and initial value.
Examples:
1) a DB 23 : defines the variable with the name “a”, data type byte (DB-Define Byte)
and initial value 23
2) a1 DW 23ABh : defines the variable with the name “a1”, data type word (DW-Define
Word) and initial value 23ABh
3) a12 DD -101 : defines the variable with the name “a12”, data type doubleword (DD-
Define DoubleWord) and initial value -101.
I.1.3 Instructions
;
; Comments are preceded by the ‘;’ sign. This line is a comment (is ignored by the assembler)
; This program computes the expression: x:= a + b – c = 3 + 4 – 2 = 5.
;
;
bits 32
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
A number is converted from a source base to a destination base. There are two algorithms that
are mostly used for converting a natural number between numbering bases: one is based upon
successive division operations and the other is based on successive multiplication operations.
Binary digit = Bit (a software concept that represents the smallest quantity of information)
Now, we can consider the reverse problem of “representation”, that is “interpretation”. Let’s
assume that the binary content of the AL register is 1110 1111 and the next instruction to be
executed is:
mul bl
The mul instruction just multiplies the value from the AL register with the value from the BL
register and stores the result in AX (more details about the mul instruction will be given in
seminar no. 2). When the CPU executes the above instruction it needs to ask itself the question
(the human programmer also asks himself the same question): what integer number does the
sequence of bits from AL (i.e. 1110 1111) represents in our conventional numbering system (i.e.
base 10)? The CPU must interpret the sequence of bits from AL into a number in order to
perform the mathematical operation (multiplication).
Just like we have two types of “representations”, we also have two corresponding types of
“interpretations”: signed interpretation and unsigned interpretation.
In our example where we have in the AL register the sequence of 8 bits: 1110 1111, this value
can be interpreted:
unsigned: in this case, we now that in the unsigned representation, only positive numbers
are represented, so our sequence of bits represents a positive number and it is the
representation in base 2 of that number; so the number in base 10 is:
1*2^7 + 1*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 1* 2^2 + 1*2^1 + 1*2^0=
128 + 64 + 32 + 0 + 8 + 4 + 2 + 1 = 239
signed: in this case, we know that in the signed representation the most significant bit of
the representation is the sign bit; our sign bit is 1 which means that this is the signed
representation of a negative number; in other words this is the complementary code
representation of the negative number; in order to obtain the direct code (the
representation in base 2 of the absolute value of the number) we use the following rule:
take all the bits of the complementary code representation, from right to left, keep all the
bits until the first 1, including this one, and reverse the remaining bits (1 becomes 0, 0
becomes 1). So, for our example of 1110 1111, the direct code is: 0001 0001 = 17. So the
sequence of 8 bits 1110 1111 from the memory is interpreted signed into the number -17.
On the IA-32 architecture, related to the unsigned and signed representation of numbers, there
are 3 classes of instructions:
instructions which do not care about signed or unsigned representation of numbers: mov,
add, sub
instructions which interpret the operands as unsigned numbers: div, mul
instructions which interpret the operands as signed numbers: idiv, imul, cbw, cwd, cwde
It is important to be consistent when developing a IA-32 assembly program: either consider all
numerical values in a program to be unsigned (in which case you should use only instructions
from class 1 and 2) or consider all numerical values in a program to be signed (in which case you
should use only instructions from class 1 and 3).