What is the difference between Times and Dup in Assembly Language?

In a bootloader, the second last line is :

TIMES 510-($-$$) db 0

Now, will this command also do the same :

db 510-($-$$) DUP (0)

If not why?

I know what TIMES does, but its not mentioned in my x86 book by Mazidi (Pearson Publication). Any idea why?

And what is the meaning of the $ sign exactly? Different sites have different information about $.

And is the line TIMES 510-($-$$) db 0 absolutely necessary even if my bootloader code is of 512 bytes in size?

So can anyone help me with these questions?

TIMES and DUP are assembler specific commands, and as such aren’t part of x86 assembly language. Same goes for $ and $$.

The $ symbol denotes the current address of the statement, and the $$ denotes the address of the beginning of current section. So the lines with DUP and TIMES calculate the current address in the section and subtracts it from 510. This effectively just zeroes out the section from the beginning to the current address.

2

DUP is a specific operand specifier to the DB/DW/etc psuedo-instructions, telling them to repeat a specific value. It can only be used in these data instructions.

TIMES is a generic instruction prefix, telling the assembler to produce multiple copies of the instruction (or psuedo-instruction), whatever it may be.

AFAIK, TIMES is specific to NASM, whereas DUP is widely supported. The reason why TIMES is used in NASM is that one of the primary design goals of NASM was to simplify the use of directives and provide more logical, rational ways of doing things. TIMES can be used in the way you show to fill a space with zeroes, but there are other applications (e.g. aligning loops by generating a sequence of NOP or similar instructions), and this way a single directive can handle multiple jobs. I actually wasn’t aware that DUP was supported in NASM at all. I guess DUP was added in a later version for compatibility with MASM-style syntax; I’m not quite sure when; certainly it was quite late, with the result that the documentation doesn’t report that it’s available), but TIMES is preferred (at least by the original authors of NASM) as being a more generally useful directive.

As to the meaning of $, the reason for different sites having different descriptions is probably again due to the NASM/MASM distinction. In NASM, $ is a variable that contains the address at which the current instruction will be assembled. Note that as it is an address, it may be subject to relocation or otherwise changed during linking. It therefore cannot be used in the TIMES instruction, whose value must be determinable at the point of assembly (it is a critical expression). $$ is the address of the start of the section, so $ - $$ is an offset, which is not subject to relocation and can therefore always be turned into a number. In MASM, $ has the same meaning, but there is no equivalent $$ variable (I believe you would achieve the same things using the WRT operator, but it has been a while since I used MASM so I’m not sure about that).

This should allow you to work out the answer to your third question: TIMES 510-($-$$) db 0 does nothing if $-$$ is equal to 510 because the number of repetitions becomes 0, so if you know that your code is already 512 bytes long you do not need it.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật