Jump to content

Assembly: Print string code with BIOS interrupts won't work

SIGSEGV

Printing one character works perfectly fine, but trying to make it loop through a word doesn't...

;the actual codesection .textglobal StartStart:     	MOV AX, 0x7C0          ;set ax to 112, this is where the BIOS puts us so start there, 0x7c0=112	MOV SI, welcome	CALL _PRNTSTR	MOV AL, 'X'	CALL _PRNTCHR	MOV AL, 'D'	CALL _PRNTCHR	JMP $ 		;Infinite loop, hang it here._PRNTCHR:			;_PRNTCHR function: Prints the character in register AL	MOV AH, DRAW_TEXT	;Tell BIOS that we need to print one character on screen.	MOV BH, 0x00		;Page no. We're not gonna be double buffering so just keep this as 0	MOV BL, 0x07		;Text attribute 0x07 is lightgrey font on black background	INT VIDEO_INTERRUPT	;Call video interrupt	RET			;Return to calling procedure_PRNTSTR:	PrintCharacterInString:		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 	;If end then return		CALL _PRNTCHR		JMP PrintCharacterInString	_EXIT:	RETTIMES 510 - ($ - $$) db 0	;Fill the rest of sector with 0DW 0xAA55			;Add boot signature at the end of bootloader;storing stuffsection .dataDRAW_TEXT equ 0x0EVIDEO_INTERRUPT equ 0x10welcome db 'TEST', 0

"My game vs my brains, who gets more fatal errors?" ~ Camper125Lv, GMC Jam #15

Link to comment
Share on other sites

Link to post
Share on other sites

about half way trough the entire thing turns into a comment string, i'm guessing thats an issue with the code tag, and is not actually the case in your IDE?

 

other than that, my assembly knowledge is a tad rusty, and i cant really spot any flaws...

Link to comment
Share on other sites

Link to post
Share on other sites

about half way trough the entire thing turns into a comment string, i'm guessing thats an issue with the code tag, and is not actually the case in your IDE?

 

other than that, my assembly knowledge is a tad rusty, and i cant really spot any flaws...

Yeah, the code tag does that when it sees the apostrophe in one of my comments

"My game vs my brains, who gets more fatal errors?" ~ Camper125Lv, GMC Jam #15

Link to comment
Share on other sites

Link to post
Share on other sites

You forgot to update your data segment register to the current one. I've modified a few things on your code to make it work :D

 

;the actual codesection .textglobal StartStart:    	MOV AX, 0x7C0          ;set ax to 112, this is where the BIOS puts us so start there, 0x7c0=112	MOV BX, welcome	MOV DS, AX	POP SI	CALL _PRNTSTR	MOV AL, 'X'	CALL _PRNTCHR	MOV AL, 'D'	CALL _PRNTCHR	JMP $   ;Infinite loop, hang it here._PRNTSTR:	MOV AL, byte[BX]  ;Get a byte from string and store in AL register	INC BX   	  ;Increment BX pointer	OR AL, AL   ;Check if value in AL is zero (end of string) 	JZ   _EXIT	PUSH BX	CALL _PRNTCHR     ;If end then return	POP BX	JMP _PRNTSTR_PRNTCHR:        ;_PRNTCHR function: Prints the character in register AL	MOV AH, DRAW_TEXT ;Tell BIOS that we need to print one character on screen.	MOV BX, 0x0007  ;Page no. We're not gonna be double buffering so just keep this as 0                 	;Text attribute 0x07 is lightgrey font on black background	INT VIDEO_INTERRUPT ;Call video interrupt               ;Return to calling procedure_EXIT:RET;storing stuffsection .dataDRAW_TEXT equ 0x0EVIDEO_INTERRUPT equ 0x10welcome db 'TEST', 0
Thanks it works now :)

"My game vs my brains, who gets more fatal errors?" ~ Camper125Lv, GMC Jam #15

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×