20.8k views
5 votes
Each of the following lines of code generates an error message when we invoke the assembler. Explain what is wrong with each line. Movb $0xF, (%b1) mov1 %ax, (%esp) movw (%eax), 4(%esp) movb %ah, %sh movl %eax, $0x123 movl %eax, %dx movb %si, 8(%ebp)

2 Answers

5 votes
1. `Movb $0xF, (%b1)`: There is a typo in this line. `%b1` is not a valid register or memory location. It should be replaced with a valid register or memory location.

2. `mov1 %ax, (%esp)`: There is a typo in this line. `mov1` is not a valid instruction. It should be replaced with `mov`.

3. `movw (%eax), 4(%esp)`: This line tries to move a word (2 bytes) from the memory location pointed to by `%eax` to the memory location 4 bytes above `%esp`. However, `%eax` is a 32-bit register, so it points to a memory location that is only 1 byte long. This will result in a memory access error.

4. `movb %ah, %sh`: There is no `%sh` register in x86 assembly. It should be replaced with a valid register.

5. `movl %eax, $0x123`: The destination operand of `movl` should be a register or memory location, not an immediate value. It should be replaced with a valid register or memory location.

6. `movl %eax, %dx`: `%dx` is a 16-bit register, but `%eax` is a 32-bit register. This will result in a truncation of the value in `%eax` when it is moved to `%dx`.

7. `movb %si, 8(%ebp)`: `%si` is a 16-bit register, but the destination operand is a memory location that is only 1 byte long. This will result in a truncation of the value in `%si` when it is moved to the memory location.
User Sarbbottam
by
8.5k points
0 votes

Explanation: 1. `Movb $0xF, (%b1)` - There is a typo in the instruction. It should be `Movb $0xF, (%bx)` or `Movb $0xF, (%ebx)` instead of `%b1`. The `%b1` is an invalid register reference.

2. `mov1 %ax, (%esp)` - There is a typo in the instruction. It should be `movl %ax, (%esp)` instead of `mov1`. The `1` is an invalid operand size.

3. `movw (%eax), 4(%esp)` - The instruction is trying to access memory using two addressing modes at the same time. It should be either `movw (%eax), (%esp)` or `movw 4(%eax), 4(%esp)`.

4. `movb %ah, %sh` - The `%sh` register is not a valid register in x86 architecture. It should be either `%ah` or `%bh`.

5. `movl %eax, $0x123` - The instruction is trying to move a value to a constant. It should be `movl $0x123, %eax`.

6. `movl %eax, %dx` - The destination register `%dx` is a 16-bit register, while the source register `%eax` is a 32-bit register. It should be either `movw %ax, %dx` or `movl %eax, %edx`.

7. `movb %si, 8(%ebp)` - The `%si` register is a 16-bit register, while the destination address is 8 bits. It should be either `movb %sil, 8(%ebp)` or `movw %si, 8(%ebp)` depending on the intended operation.

User Adam LeBlanc
by
7.8k points