This blog was last modified 427 days before.

Try out mov Instruction

image.png

As the image shows, we have successfully move the value into this 3 register. And we now also find out that:

  • Numbers ends with h represents Hexidemical.
  • Numbers ends with b represents Binary.
  • Otherwise, this number would be considered Decimal.

Immediate value

image.png

As the picture above said, you can directly move a immediate value into a Segment Register (CS, DS, ES and SS). But you can use the general propose register as a transition.

image.png

Except CS, other segment register could be modified by using mov and the values already stored in general proposed register.

However if you try to do the same thing to CS and IP (Code Segement Register), you would got error saying:

([Line Number]) CS cannot be modified directly (use far JMP or CALL) 

However CS is read-able, means you can do something like:

mov ax, cs

Access RAM (Random Access Memory)

We also use MOV to write thing into memory. As we learned before, command like MOV AX, BX means moving the value in register BX to AX.

However, if we store the memory address in AX, and want to move the value from BX to the memory address stored in AX, then we should wrap AX with bracket. See below:

; configure data stack register
mov cx, 0ffffh
mov ds, cx

; move data into ram
mov ax, 0b00h
mov bx, 1000h
mov ds:[ax], bx

Aware that we use ds:[ax] to specified the destination in the memory. The address been accessed is ds*16 + ax. You can consider its in schema base:[offset].

However in this case the ds: could be omitted, and mov [ax], bx will produce the identical result, since ds register would be used as the default base address register when no base address register specified.

The data write into the memory seems to support immediate number.

Now let's look back to this [ax] again. Don't you be reminded something familiar? That's acutally a pointer! In C, we would use something like int* p;, which p actually store a number, and when we add * to the p, then computer would know that we actually want to access the address that pointed by p but not the value in p itself.

Notes

image.png

You can let SIM8086 to show memory info in view > memory.

Notice that in RAM debug window, it allows you to specified a offset to the base address stored in DS. For example in the picture above I set the offset to 0000h (which means no offset), and value in D is 0f00h. So the memory debug windows would show the memory start from 0f00h.

If you want to directly check the memory in specified address, you can enter a full address in pattern base:offset like 0f00h:0000h. In this case the memory debuger will directly show the info in address you entered and will NOT add up the value in DS.

image.png

Offset Schemes

[BX + SI]
[BX + DI]
[BP + SI]
[BP + DI]	
[SI]
[DI]
d16 (offset of a variable)
[BX]	
[BX + SI + d8]
[BX + DI + d8]
[BP + SI + d8]
[BP + DI + d8]
[SI + d8]
[DI + d8]
[BP + d8]
[BX + d8]	
[BX + SI + d16]
[BX + DI + d16] 
[BP + SI + d16]
[BP + DI + d16]	
[SI + d16]
[DI + d16]
[BP + d16]
[BX + d16]

Above is the list of ALL allowed address offset expressions.

Notice when your offset address contains BP, the base address register usually default to SS, otherwise, the default base address register usually default to DS. You can experiment this behaviour yourself using the code below:

; make ss different from cs  
mov bx, ss
add bx, 3239
mov ss, bx 

; make ds different from cs  
mov bx, ds
add bx, 6239
mov ds, bx

mov ds:[1000h], 1234h
mov ss:[1000h], 5678h
mov cs:[1000h], 0ffffh


           
mov bp, 1000h
mov si, 1000h
mov di, 1000h
mov bx, 1000h 


; Use debugger to check the value in ax
; if 1234h, means ds used
; if 5678h, means ss used
; if 0ffffh, means cs used
mov ax, [bp] 
mov ax, [si]
mov ax, [di]
mov ax, [bx]   

ret