assembly output

closed account (Dy7SLyTq)
this code is supposed to output hello world, but will it actually do that? im not advanced enough in assembly to know which line

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[BITS 16]	;Tells the assembler that its a 16 bit code
[ORG 0x7C00]	;Origin, tell the assembler that where the code will
				;be in memory after it is been loaded

MOV SI, HelloString ;Store string pointer to SI
CALL PrintString	;Call print string procedure
JMP $ 		;Infinite loop, hang it here.


PrintCharacter:	;Procedure to print character on screen
	;Assume that ASCII value is in register AL
MOV AH, 0x0E	;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00	;Page no.
MOV BL, 0x07	;Text attribute 0x07 is lightgrey font on black background

INT 0x10	;Call video interrupt
RET		;Return to calling procedure



PrintString:	;Procedure to print string on screen
	;Assume that string starting pointer is in register SI

next_character:	;Lable to fetch next character from string
MOV AL, [SI]	;Get a byte from string and store in AL register
INC SI		;Increment SI pointer
OR AL, AL	;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL register
JMP next_character	;Fetch next character from string
exit_function:	;End label
RET		;Return from procedure


;Data
HelloString db 'Hello World', 0	;HelloWorld string ending with 0

TIMES 510 - ($ - $$) db 0	;Fill the rest of sector with 0
DW 0xAA55			;Add boot signature at the end of bootloader
It looks like it would, why not download a VM and try it yourself?
im not advanced enough in assembly to know which line

What do you mean which line, if you mean the line where the OS actually prints something, it is line 16 (the int 010 instruction), however you pass it its parameters in the registers you initialise before that. Also, that only prints one character, AFAIK you cannot print a whole sting in one go with BIOS calls.
Well my assembler is majorly rusty, but that looks about right. Makes me want to brush up on my assembler, but the last one I used was Emu8086 in college. Think I have a copy lying around, but also heard mips is a good one to have under you belt. Either way, your code looks right, but if you don't trust it you can always set up a virtual box to run it on so it doesn't affect anything.
closed account (Dy7SLyTq)
i installed virtual box, but i cant figure out how to get it to boot to the bootloader
You need to assemble your program and use an disk iso maker to write your program to an iso file, you then boot your VM with the iso file.
closed account (Dy7SLyTq)
yeah i found how to get the iso loaded. now to make the iso, if i do this would it work (boot.iso doesnt exist before the command)

dd if=boot.bin of=boot.iso
No, ISO files aren't like floppies, they're not a raw format. It's called ISO because it implements the ISO 9660 standard which describes a file system for optical media. To put a file on an ISO image you first need to create the image file, which needs to be at least 32 kiB in size. This makes a 64 kiB one:
1
2
isofile="boot.iso"
dd if=/dev/zero of="$isofile" bs=2048 count=32

The rest of these steps need root access. Next you have to bind it to a loop device:
1
2
loopdevice=$(losetup -f)
losetup "$loopdevice" "$isofile"

Then make an ISO 9660 filesystem on it:
mkisofs "$loopdevice"
Then mount it, copy the file and clean up:
1
2
3
4
5
inputfile="boot.bin"
mount -t iso9660 /mnt "$loopdevice"
cp boot.bin /mnt
umount "$loopdevice"
losetup -d "$loopdevice"

If you want to update the file, then you just skip the first and third steps (creating the file and making the filesystem).
Last edited on
closed account (Dy7SLyTq)
thanks... glad i asked
closed account (Dy7SLyTq)
loopdevice=losetup -f
it keeps saying error command -f not found
Try putting it in quotation marks.
closed account (Dy7SLyTq)
i did, but are you sure that its correct? it gives errors when i use it with the losetup and mkisofs
Are you using Linux, BSD, Mac OS or Windows with Cygwin/MinGW?

If Linux, you may not have mkisofs installed, but you should definitely have losetup and it should definitely accept the -f argument. The 'f' is for "free", losetup -f should return the first free loop device. You should be able to find a package containing mkisofs with your package manager's search function, e.g. apt-cache search mkisofs. If not, you can download it here: http://freecode.com/projects/mkisofs

If you're using BSD or Mac OS, then there is a different command than losetup (vnconfig), but mkisofs should be the same.

If Cygwin/MinGW, you'll need to install both mkisofs and losetup, but I don't know if they're even available. I imagine they would be, though.
closed account (Dy7SLyTq)
I'm on linux and I have both of the commands but have me assign losetup -f to a variable then pass it to losetup, which becomes losetup losetup -f
Oh yeah, sorry, my mistake; it should be loopdev=$(losetup -f).
closed account (Dy7SLyTq)
so to make sure i understand (im a little rusty in my shell speak :} )

#Load Flash Drive
$ cd $PATH_OF_BOOTLOADER
$ isofile="boot.iso"
$ dd if=/dev/zero of="$isofile" bs=2048 count=32
$ sudo su
# loopdevice=$(losetup -f)
# losetup "$loopdevice" "$isofile
# mkisofs "$loopdevice"
# inputfile="boot.bin"
# mount -t iso9660 /mnt "$loopdevice"
# cp boot.bin /mnt
# umount "$loopdevice"
# losetup -d "$loopdevice"
Aside from the unmatched quote mark here: # losetup "$loopdevice" "$isofile , yes, that looks right.

Remember, you don't need to call dd or mkisofs every time unless you want to recreate the file from scratch.
closed account (Dy7SLyTq)
ok thanks. its still saying No such File or Directory at # losetup "$loopdevice" "$isofile"
What is the output of losetup -f? I may have gotten the parameters the wrong way around, but I think it's right.
Topic archived. No new replies allowed.