Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the colon : mean in x86 assembly GAS syntax as in %ds:(%bx)?

I am new to x86 assembly and I am trying to understand the code in this document : http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf page 3 :

movw $0x1234, %ax
movw %ax, %ds
movw $0x5678, %bx
# The following instruction is the same as "movw $0x1337, (%bx)".
movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8.
# Segment Base: %ds << 4: 12340
# Offset: %bx: + 5678
# -------
# Linear Address: 179b8

But I am not understanding the command :

movw $0x1337, %ds:(%bx) # Places 0x1337 into memory word 0x179b8.

Why concatenating %ds with (%bx) is the same as ((%ds << 4) | %bx) ?

As I am in real mode (16 bits), the concatenation shouldn't be %ds << 8 ? instead of %ds << 4?

And why the parenthesis is just around %bx? And not around the whole structure like : movw $0x1337, (%ds:%bx) ?

like image 283
Lilás Avatar asked Sep 11 '13 08:09

Lilás


People also ask

What does colon mean in assembly?

A colon separates the assembler template from the first output operand and another separates the last output operand from the first input, if any. Commas separate the operands within each group.

What does DS mean in assembly?

The ds: means the instruction is referencing memory in the Data Segment - and can pretty much be ignored on modern OSes, since they run with a flat address space model (code, data and stack segments all refer to the same memory range, and memory protection is handled with paging).

What does Q mean in assembly?

q = quad (64 bit). t = ten bytes (80-bit floating point).

What are the three types of operands in x86?

Operands can be immediate (that is, constant expressions that evaluate to an inline value), register (a value in the processor number registers), or memory (a value stored in memory).


1 Answers

In real mode, the segment register is used to provide a 20-bit address. In this case, the data segment register ds provides the 'high' 16 bits of the address: (0x1234 << 4 = 0x12340), and the offset in the segment is given by: 0x5678, to yield: 0x179b8.

The data segment register is implicit, so it's not necessary to use: ds:(%bx). If you were using another segment register, like es, it would need to be explicit.

I hope I've understood your question. As to why it's not written as (%ds:%bx), that's really just a syntactic decision that you're stuck with.

like image 90
Brett Hale Avatar answered Sep 28 '22 20:09

Brett Hale