In: Computer Science
1a)What is the purpose of suffixes on commands? Are suffixes required? (defend your answer)
b)Describe 3 types of mov commands, i.e. data located in source and destination postions
c)Describe how the jmp command works and list the different "jump" commands and their task/meaning.
d)Describe how leaq works. Can leaq be used for arithemetic operations? (explain)
a)
A suffix is a letter or group of letters added to the end of a word. Suffixes are commonly used to show the part of speech of a word. For example, adding "ion" to the verb "act" gives us "action," the noun form of the word. Suffixes also tell us the verb tense of words or whether the words are plural or singular.
RULE: 1 - When a word ends with a consonant and the suffix begins with a consonant, just add the suffix with no spelling changes. RULE: 2 - For most words ending in a single consonant you need to double the last letter when you add suffixes. This is especially true for one syllable words!
The most common suffixes are: -tion, -ity, -er, -ness, -ism, -ment, -ant, -ship, -age, -ery.
I’m surprised nobody has mentioned suffixes to actual names, such as in Lithuanian.
Take a person from that country with the surname “Paulauskaitė”. I know, without meeting her or knowing her first name, that this is an unmarried woman - because the suffix “-aitė” gives it away. A married woman or a widow would be named “Paulauskienė”; the father / husband would be “Paulauskas”.
More recently, it has been formally accepted for women to use a simple “-ė” suffix to conceal their marriage status (“Paulauskė”), similar to the “Ms” prefix negating the need to distinguish a “Mrs” from a “Miss”. This status-neutral suffix has been slower to catch on in Lithuanian than the prefixed title in English, but will likely become more common in future as social attitudes change.
b)
Register Addressing
In this addressing mode, a register contains the operand. Depending upon the instruction, the register may be the first operand, the second operand or both.
For example,
MOV DX, TAX_RATE ; Register in first operand MOV COUNT, CX ; Register in second operand MOV EAX, EBX ; Both the operands are in registers
Immediate Addressing
An immediate operand has a constant value or an expression. When an instruction with two operands uses immediate addressing, the first operand may be a register or memory location, and the second operand is an immediate constant. The first operand defines the length of the data.
For example,
BYTE_VALUE DB 150 ; A byte value is defined WORD_VALUE DW 300 ; A word value is defined ADD BYTE_VALUE, 65 ; An immediate operand 65 is added MOV AX, 45H ; Immediate constant 45H is transferred to AX
Direct Memory Addressing
When operands are specified in memory addressing mode, direct access to main memory, usually to the data segment, is required. This way of addressing results in slower processing of data. To locate the exact location of data in memory, we need the segment start address, which is typically found in the DS register and an offset value. This offset value is also called effective address.
In direct addressing mode, the offset value is specified directly as part of the instruction, usually indicated by the variable name. The assembler calculates the offset value and maintains a symbol table, which stores the offset values of all the variables used in the program.
In direct memory addressing, one of the operands refers to a memory location and the other operand references a register.
For example,
ADD BYTE_VALUE, DL ; Adds the register in the memory location MOV BX, WORD_VALUE ; Operand from the memory is added to register
c)
The machine cycle automatically executes instructions in sequence. When a jump instruction executes (in the last step of the machine cycle), it puts a new address into the PC. Now the fetch at the top of the next machine cycle fetches the instruction at that new address.
d)
The LEA (Load Effective Address) instruction is a way of obtaining the address which arises from any of the Intel processor's memory addressing modes. That is to say, if we have a data move like this: MOV EAX, <MEM-OPERAND> it moves the contents of the designated memory location into the target register.
The lea instruction calculates the address of the src operand and loads it into the dest operand. Note Load Effective Address calculates its src operand in the same way as the mov instruction does, but rather than loading the contents of that address into the dest operand, it loads the address itself.
Yes arithmatic operation is possible.
As others have pointed out, LEA (load effective address) is often used as a "trick" to do certain computations, but that's not its primary purpose. The x86 instruction set was designed to support high-level languages like Pascal and C, where arrays—especially arrays of ints or small structs—are common. Consider, for example, a struct representing (x, y) coordinates:
struct Point
{
int xcoord;
int ycoord;
};
Now imagine a statement like:
int y = points[i].ycoord;
where points[]
is an array of Point
.
Assuming the base of the array is already in EBX
, and
variable i
is in EAX
, and
xcoord
and ycoord
are each 32 bits (so
ycoord
is at offset 4 bytes in the struct), this
statement can be compiled to:
MOV EDX, [EBX + 8*EAX + 4] ; right side is "effective address"
which will land y
in EDX
. The scale
factor of 8 is because each Point
is 8 bytes in size.
Now consider the same expression used with the "address of"
operator &:
int *p = &points[i].ycoord;
In this case, you don't want the value of ycoord
,
but its address. That's where LEA
(load effective
address) comes in. Instead of a MOV
, the compiler can
generate
LEA ESI, [EBX + 8*EAX + 4]