OSDev.org https://forum.osdev.org/ |
|
Printing register values problem https://forum.osdev.org/viewtopic.php?f=1&t=31412 |
Page 1 of 1 |
Author: | atilali [ Sat Mar 11, 2017 6:59 am ] |
Post subject: | Printing register values problem |
Hi i am trying to print register values on the screen. at line 14 if i set ax manually like "mov ax,0xffff;" it works fine. but when i type "mov ax,bx" it fills screen with random characters. im trying to find problem over 2 hours Code: mov ax,0xb800;
mov es,ax; mov ax,0x07c0; mov ds,ax; xor ax,ax; mov di,ax; mov ax,disk_drive_number; mov si,ax; call printStr; mov ax,bx; call printInt; call jmp; ;prints ax to screen printInt: mov cx,0x0000; divide: mov dx,0x0000; mov bx,0x000A; div bx; inc cx; add dx,48; mov dh,0x4e; push dx; cmp ax,0x0000; jne divide; print: pop dx; mov di,[video_memory_index]; mov [es:di], dx; inc di; inc di; mov [video_memory_index],di; dec cx; cmp cx,0x0000; jne print; ret; ;prints string in [ds:si] to screen printStr: cld;inc si after lodsb loadchr: lodsb; cmp al,0x00; je printStrFinish; cmp al,0x0A; je newline; mov ah,0x4e; mov di,[video_memory_index]; mov [es:di],ax; inc di; inc di; mov [video_memory_index],di; jmp loadchr; newline: push dx; push bx; push ax; mov bx,0x00A0; add [video_memory_index],bx; mov dx,0; mov ax,[video_memory_index]; div bx; sub [video_memory_index],dx; pop ax; pop bx; pop dx; jmp loadchr; printStrFinish: ret; jmp: nop call jmp video_memory_index dw 0x00A0; disk_drive_number db 'drivenumber:',0x00; ax_str db 'ax:',0x0A,0x00; bx_str db 'bx:',0x00; cx_str db 'cx:',0x00; dx_str db 'dx:',0x00; sp_str db 'sp:',0x00; bp_str db 'bp:',0x00; si_str db 'si:',0x00; di_str db 'di:',0x00; times 510-($-$$) db 0 db 0x55 db 0xAA |
Author: | Octacone [ Sat Mar 11, 2017 7:13 am ] |
Post subject: | Re: Printing register values problem |
atilali wrote: Code: mov ax,0xb800; Just a hint. If this indicates your video memory, it is wrong. It should be 0xB8000. |
Author: | atilali [ Sat Mar 11, 2017 7:17 am ] |
Post subject: | Re: Printing register values problem |
octacone wrote: atilali wrote: Code: mov ax,0xb800; Just a hint. If this indicates your video memory, it is wrong. It should be 0xB8000. Hi, i am in real mode. using ax to load es with 0xb800. when i write to video memory i use [es:di] so i think its not wrong. |
Author: | BrightLight [ Sat Mar 11, 2017 7:20 am ] |
Post subject: | Re: Printing register values problem |
octacone wrote: atilali wrote: Code: mov ax,0xb800; Just a hint. If this indicates your video memory, it is wrong. It should be 0xB8000. That code is correct. He's obviously running in real mode, and he loads the ES segment with 0xB800, which would allow him to access 0xB8000 through DI register (or any other register/instruction with ES prefix.) OP: While I haven't reviewed the code, what exactly happens when your code is run? Try different values and tell us what is printed, for example, try 0x1234, 0x1A2B and 0xFFFF. |
Author: | Octocontrabass [ Sat Mar 11, 2017 7:21 am ] |
Post subject: | Re: Printing register values problem |
atilali wrote: Code: jmp: nop call jmp What does this do? |
Author: | Octacone [ Sat Mar 11, 2017 7:28 am ] |
Post subject: | Re: Printing register values problem |
omarrx024 wrote: octacone wrote: atilali wrote: Code: mov ax,0xb800; Just a hint. If this indicates your video memory, it is wrong. It should be 0xB8000. That code is correct. He's obviously running in real mode, and he loads the ES segment with 0xB800, which would allow him to access 0xB8000 through DI register (or any other register/instruction with ES prefix.) OP: While I haven't reviewed the code, what exactly happens when your code is run? Try different values and tell us what is printed, for example, try 0x1234, 0x1A2B and 0xFFFF. Oops! Sorry, forgot about segment:offset. Octocontrabass wrote: atilali wrote: Code: jmp: nop call jmp What does this do? I tried running his code and it crashed. When I removed that part crashes were gone. |
Author: | atilali [ Sat Mar 11, 2017 7:31 am ] |
Post subject: | Re: Printing register values problem |
Octocontrabass wrote: atilali wrote: Code: jmp: nop call jmp What does this do? Does nothing i suppose its called after printing on screen to keep cpu busy. |
Author: | atilali [ Sat Mar 11, 2017 7:38 am ] |
Post subject: | Re: Printing register values problem |
omarrx024 wrote: OP: While I haven't reviewed the code, what exactly happens when your code is run? Try different values and tell us what is printed, for example, try 0x1234, 0x1A2B and 0xFFFF. outputs for 0x1234, 0xFFF and mov ax,bx : http://imgur.com/a/2i6hj |
Author: | Brendan [ Sat Mar 11, 2017 7:42 am ] |
Post subject: | Re: Printing register values problem |
Hi, Some tips:
Cheers, Brendan |
Author: | atilali [ Sat Mar 11, 2017 7:55 am ] |
Post subject: | Re: Printing register values problem |
Brendan wrote: [*]The "call" instruction pushes a return address on the stack. A loop like "jmp: call jmp" would never remove these return addresses from the stack, and will quickly fill the stack with worthless trash until bad things happen (until useful data is overwritten or you get some kind of stack fault or exception). You would need a loop like "jmp: jmp jmp" (which also serves as a nice example of why you shouldn't give a label the same name as an instruction). i guess this was the problem. stack has been overriding video memory. i have changed jmp to Code: jmp: jmp jmp and it worked. thanks |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |