I need to understand this more and this answer that people are copying as their
ID: 3808560 • Letter: I
Question
I need to understand this more and this answer that people are copying as their own answers is not helping. Please do not copy and paste this...
"1)In this first first code the movb $0xF, (%ql) .In this (%ql) is not corrctly mentioned .And also you dono't say the what processor.q1 is a 8 bit register atleast in x86 processors.But itcannot be used in addressing.
An assembly instruction is invalid is that there is no such instruction for the given processor. There is no possible way to encode this instruction. In this case (assuming x86), using bl or any other 8-bit register neither for addressing has not been considered necessary.
2)In this second code movl %eax,$0xFA.In this we cannot use %eax as a address register.And the %eax is a 32 bit register.
3) In this third code movl %eax,%bx as mentioned that %eax as a address register.And the %eax is a 32 bit register.bx is the memory location whose address is contained in the register eax
4)In this fourth movb %ah,%sh here we have mentioned as a register addressing but this is not a correct format to move one address to the another address.
5) In this fifth movw 4(%esp), (%ebx) this instruction is also not valid because %ebx as a address register.And the %ebx is a 32 bit register.bx is the memory location whose address is contained in the register esp"
Each of the following lines of code generates an error message when we invoke the assembler. Explain what is wrong with each line.
1 movb $0xF, (%ql)
2 movl %eax,$0xFA
3 movl %eax,%bx
4 movb %ah,%sh
5 movw 4(%esp), (%ebx)
Explanation / Answer
I don't want to confuse you with all complicated information. I will try to explain in a simple way
Note : movb moves one byte data, movl moves 32-bit of data, movw moves 64-bit of data. The suffixes, b, l, w indicates it.
------------------------------------------------------------------------------------------------------------------
3. movl %eax,%bx
It is illegal because the operand sizes are mismatch. movl tries to moves 32-bit data from EAX to the register BX. But the problem is that BX regiseter is only 16-bit, so cannot it hold 32-bit data!
-------------------------------------------------------------------------------------------------------------------
1. movb $0xF, (%bl) is illegal
Example :
The following example moves 8-bit integer representation of '2' into the address stored in EBX. Since EBX is a 32-bit register, the address used is a 32-bit address.
movb $2, (%ebx)
Reason : BL is not allowed to be used in addressing. Why?
The only allowable registers for a 16-bit processors are BX, BP, SI, DI. These registers are 16-bit wide, so they can store an address of 16-bit. We use these registers because they can hold 16-bit address.
And the allowable registers for a 32-bit processors are EAX, EBX, ECX, EDX, ESP, EBP, ESI, EDI. All these registers are 32-bit wide and can store 32-bit address. We use these registers because they can hold 32-bit address.
Since your processor(x86) is either a 16-bit or 32-bit, you can use only the above mentioned registers according to the processor. This is because the respective registers should be able to hold the complete address.
Now see why the command is actually illegal! Your processor uses an address of 16-bit (or 32-bit). But the command says use the address stored at BL, which is just 8-bits!
Imagine, if you had a processor, (where address size is 8-bit). In this case, you could have used BL register, which holds an 8-bit address to refer to a location.
-------------------------------------------------------------------------------------------------------------
2. movl %eax, $0xFA
movl moves a 32-bit data to the given destination. The reason it is illegal is because the given instruction format is not specified in the instruction set. Consider the following valid instruction formats.
movl $0x00FA %eax /*Moves the word “0x00FA” to EAX register */
movl $0x00FA (%eax) /*Moves the word to the location stored in EAX register */
movl (%eax) eax /*Moves the contents at the memory locations in eax to eax */
movl (%edx) (%eax) /*Moves from one memory location to other *
----------------------------------------------------------------------------------------------------------------------
5 movw 4(%esp), (%ebx)
movw tries to moves 64-bit of data at location (ESP)+4, to the destination location specified. EBX cannot be used as addressing register here. Note that EBX is only a 32-bit register.
----------------------------------------------------------------------------------------------------------------------