I am sorry for asking this as it probably is a stupid question, but I am at a loss.

I am 17 years old and brand new to ASM.  I am trying to learn it because I do not like the idea of relying on other peoples code.  I want to be able to make something entirely from scratch.  In the field of programming I am a do it yourself guy.  By the way, that is why I do not like the Cloud.

I am writing OS level code.  Therefore, I am using PXE booting with a bridged VirtualBox network connection to test it.  I do this by specifying my program as the file on the server to boot to.

I have written a previous program out of samples that worked fine(In the aspect I am asking in this question as It still has other bugs).  However my new program(based off those same samples) is not correctly retrieving values stored in memory.  I have written a basic program to demonstrate what is happening.  Most of the code is just to write the characters on the screen, but the issue is this. I define the decimal ASCII value of a character I would like to print and store it in memory.  Then I go to retrieve it and print it out.  I should see the character I defined, but that is never what happens.  However, if I directly send the character to be printed to the screen, it works fine.

Here is the program that does not work:
	;tell the assembler that its a 16 bit code
;Origin, tell the assembler that where the code will
;be in memory after it is been loaded

JMP declar

;Declare

xpoint DB '+'
ypoint DB 45

PrintChar:
MOV AH, 0x0E ;Teletype Write Text Int Type
MOV BL, 0x02 ;Set Color (Based on windows cmd colors)
MOV BH, 0x00 ;page number (text modes)
INT 0x10 ;Video Int
RET

declar:

;Wait For Keypress
MOV AH, 0
INT 0x16

redraw:

;Clear Screen
MOV AH, 0x00 ;Should Always Be 0 for this op
MOV AL, 0x12 ;Set Graphics Mode
INT 0x10 ;Video Int

;MOV SI, xpoint
MOV AL,
CALL PrintChar
MOV AL, '|'
CALL PrintChar
MOV SI, ypoint
MOV AL,
CALL PrintChar

idle:
JMP idle ;infinite loop

;TIMES 510 - ($ - $$) db 0 ;fill the rest of sector with 0
DW 0xAA55 ;Bootloader Verify



Here is the one that does(Pay no attention to the comments.  They are not accurate.  Bad I know.  I also just realized that the initial line of text is not being displayed.  I do, however, remember it working before.  I may have made a change that broke it.  At this time, I can not find the problem.  Do not worry to much about this code though.  It was just something I was messing and practicing with a while back.):
	;Tells the assembler that its a 16 bit code
;Origin, tell the assembler that where the code will
;be in memory after it is been loaded

MOV SI, TextEntry
MOV , SI
MOV AH, 00h
MOV AL, 12h
INT 10h ;Call video interrupt
MOV SI, helloMichael
CALL PrintString
JMP idle ;Infinite loop, hang it here.


PrintString: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AL,
INC SI
OR AL, 0
JZ exit_function_000
MOV AH, 0Eh ;Tell BIOS that we need to print one charater on screen.
MOV BH, 00h ;Page no.
MOV BL, 0Ah ;Text attribute 0x07 is lightgrey font on black background
INT 10h ;Call video interrupt
CALL PrintString
exit_function_000:
RET

idle:

;Check If Keyboard Has Been Pressed
MOV AH, 01h
INT 16h
JNZ getKeyPress_go
getKeyPress_ret:
check_for_key_events_ret:
write_new_line_ret:
save_and_print_key_ret:
MOV AL, 0
MOV , AL

;Loop
JMP idle

getKeyPress_go:
MOV AH, 00h
INT 16h
MOV , AL
JMP check_for_key_events

check_for_key_events:

MOV AH,
CMP AH, 1Bh
JE dloop

MOV AH,
;JMP save_and_print_key

MOV SI, KeyPressed
CALL PrintString

JMP check_for_key_events_ret

dloop:
JMP $

save_and_print_key:
MOV AL, AH
MOV SI, TextPointer
MOV , AL
INC SI
MOV , SI
MOV , AL
MOV SI, KeyPressed
CALL PrintString
JMP save_and_print_key_ret

write_new_line:
MOV AL, 0Ah
MOV , AL
MOV SI, KeyPressed
CALL PrintString
MOV AL, 0Dh
MOV , AL
MOV SI, KeyPressed
CALL PrintString
MOV AL, 0
MOV , AL
ADD AX, 4
MOV , AX
MOV SI, Result_part_0
CALL PrintString
MOV SI, KeyPressed
CALL PrintString
MOV SI, Result_part_1
CALL PrintString

JMP $

JMP write_new_line_ret

;Data
helloMichael db 'Hello.', 0Ah, 0Dh, 'Enter Any Text You Would Like Below.', 0Ah, 0Dh, 'Press Esc To Stop The System From Accepting Text.', 0Ah, 0Dh, 0Ah, 0Dh, 0
Result_part_0 db 'Your Number Plus 4 is: '
Result_part_1 db '.', 0Ah, 0Dh, 0
Line db 'Line', 0Ah, 0Dh, 0
Shut db 'Shutting Down', 0Ah, 0Dh, 0

;Vars
KeyPressed db 0
PrintStopper db 0
TextPointer db 0
TextEntry db 0

TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55


I have read many articles and various pages of documentation, but I can not find the problem.  I am fairly certain it is a stupid one, though.  Thank you for your help.
Posted on 2012-06-19 21:33:40 by Quantum
The PrintString routine may cause a stack overflow, has a recursive call to itself generally JMP PrintString would better after the int 10 call.

Posted on 2012-06-20 00:31:04 by forthnutter
Thank you, but I still do not know what the issue is in the first program.  Also, that did not fix the problem.
Posted on 2012-06-20 09:49:53 by Quantum
Are you being thrown off by your own "Wait For Keypress" code?

Also, I don't see any explicit setup of the segments or the stack, so you are relying on unknown values. Such an assumption may cause intermittent failures. Note that this includes assumptions about the value of the CS register, some BIOS implementations will set CS to 07C0 with an initial IP of 0, while others will set CS to 0 with an initial IP of 7C00. In short, remove all assumptions.
Posted on 2012-06-20 10:41:45 by SpooK
Well setting the DS register to 0 fixed it!  Thank you!  I am very new to assembler.
Posted on 2012-06-20 17:55:07 by Quantum