Explanation of a few lines in Assembly

旧城冷巷雨未停 提交于 2019-12-12 05:49:44

问题


bits 16

org 0x7c00

start: jmp loader

;******; ; OEM Parameter block ;********;

TIMES 0Bh-$+start DB 0; THIS LINE

bpbBytesPerSector: DW 512 

bpbSectorsPerCluster: DB 1

bpbReservedSectors: DW 1

bpbNumberOfFATs: DB 2 

bpbRootEntries: DW 224 

bpbTotalSectors: DW 2880 

bpbMedia: DB 0xF0 

bpbSectorsPerFAT: DW 9 

bpbSectorsPerTrack: DW 18

bpbHeadsPerCylinder: DW 2

bpbHiddenSectors: DD 0 

bpbTotalSectorsBig: DD 0 

bsDriveNumber: DB 0 

bsUnused: DB 0 

bsExtBootSignature: DB 0x29 

bsSerialNumber: DD 0xa0a1a2a3 

bsVolumeLabel: DB "MOS FLOPPY "

bsFileSystem: DB "FAT12   "

;******** ; Bootloader Entry Point ;**********;

loader:

cli 

hlt 

times 510 - ($-$$) db 0 

dw 0xAA55 

Now the problem is I don't quite understand what TIMES 0bh-$+start evaluates to in this case. For Example $-$$ = size of the program. Also it will be really heĺpful if someone can explain to me the LODSB Syntax. Also why is there a : sign after each of those bpb and bs statements? Doesn't the : sign mean the beginning of a new section, just as in case of loader section or start section in this program. Please explain in detail how the following evaluates to the answer.

Thanks.


回答1:


Ah! "THIS LINE" just reserves space for "OEMNAME". Put the name of your OS there, if you like - padded to 11 bytes. ($$ is the same as "start" - beginning of section - 0x7C00 - in this case).

Not much "syntax" to lodsb, it's just an instruction... http://home.myfairpoint.net/fbkotler/nasmdocc.html#section-A.4.141 (did I confuse you using "lodbs" as an example of a typoed instruction? Sorry.)

The ":" does absolutely nothing. In the case of a label alone on a line, it informs Nasm that it is intended to be a label, and isn't a typoed instruction. Look in the Manual for "orphan_label". Nasm will (optionally - default ON) warn if there's no ":", but does the right thing anyway.

You really ought to have a nop after jmp start, since Nasm will emit a "short" jmp (older versions of Nasm defaulted to a near jmp). Since the entire purpose of "THIS LINE" is to put the remaining BPB variables in the right place, might as well do it!



来源:https://stackoverflow.com/questions/14906924/explanation-of-a-few-lines-in-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!