printing problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: printing problem

Post by Combuster »

*bleep* segmentation fault - executing data *bleep*

Seriously, if your really had some programming skills you'd have figured this by now. And then asking us to write your code. :shock:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: printing problem

Post by ru2aqare »

GhostXoPCorp wrote: with Hello it prints <"||pk"
with hello = h
it will print h only
can you modify my code a littlebit to help me please?
See my earlier post about some BIOSes trashing your registers...
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: printing problem

Post by neon »

There are several basic assembly language problems wrong with that code:

-The string hello db 'Hello',0 will be executed as instructions;
-The print function will be executed next with no paramater passed. When its ret instruction is executed, you will go to some random place in memory (your call print instruction is never reached)
-The code does not end anywhere so it will continue executing (assuming it somehow makes it that far) beyond your program in memory into garbage land.

Try this:

Code: Select all

org 100h
use16

mov si, hello
call print

cli
jmp $

print: 
; This code assumes that DS:SI is pointing to a NULL terminated string
push ax ; Save AX in case changing it will mess up anything 
mov ah, 0x0E ; Set AH to 0x0E, because we will be using teletype output

@@: ; The main loop
lodsb ; Load the next byte from DS:SI into AL and update SI
cmp al, 0x00 ; Is is NULL (Have we reached the end of the string)?
je @f ; YES? Then exit the loop
int 0x10 ; NO? Then print it using BIOS function 0x10 AH=0x0E
jmp @r ; Continue in our loop

@@: ; Leaving the main loop
pop ax ; Restore AX, because we pushed it to the stack earlier
ret ; Return to the calling code

hello db 'Hello',0
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: printing problem

Post by kmtdk »

well
first:

Code: Select all

org 100h
use16
hello db 'Hello',0
is perfect

except from the real problem
this is what the CPU sees, when it start to run your program:

Code: Select all

dec     ax
db      65h
insb
insb
outsw
-----
print:
; This code assumes that DS:SI is pointing to a NULL terminated string
push ax ; Save AX in case changing it will mess up anything
mov ah, 0x0E ; Set AH to 0x0E, because we will be using teletype output

@@: ; The main loop
lodsb ; Load the next byte from DS:SI into AL and update SI
cmp al, 0x00 ; Is is NULL (Have we reached the end of the string)?
je @f ; YES? Then exit the loop
int 0x10 ; NO? Then print it using BIOS function 0x10 AH=0x0E
jmp @r ; Continue in our loop

@@: ; Leaving the main loop
pop ax ; Restore AX, because we pushed it to the stack earlier
ret ; Return to the calling code 
mov si, hello
call print
well
com on.
is it your secound day ???
first
it ALWAYS start from the begining
so a fast solution would be to put a jmp in the start
like this:

Code: Select all

org 100h
use16
jmp start
where "start" is a label definded later in the code, where the "main" part is supossed to be.

it got to late to make this answer first ...

KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: printing problem

Post by VolTeK »

thank you, i was not asking for any smart mouth comments, just this, thanks. osdev was made for people who needed help, not for people who have nothing else to do but put retarded things and smart off to people who have just started programming in assembly. lives like that belong nerds who still live with there moms. i got my info, you can reply to this comment again on how mad you are now that i said all that. i wont care ill just get back on with my life. but i dont mean you kmtdk, you helped, and yes, yet i have looked at for atleast a month now, and i still dont understand some basics.
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: printing problem

Post by stephenj »

A pm from Ghost:
oh i see, your one of those people who find even a little bit in a persons conversation, and make fun of it, you have too much time on your hand, tell me do you live with your mom?
Believe it or not, what I said wasn't really intended to be in jest. What I attempted to do, poorly, is illustrate what you are saying in a way that you may relate to. Everyone on this forum has had to learn, and an important part of learning programming is learning how to read manuals and books on your own. Asking for help from someone who has taken the time to read the manuals, without bothering to do so yourself is one of the worst sins a programmer can commit.
osdev was made for people who needed help, not for people who have nothing else to do but put retarded things and smart off to people who have just started programming in assembly.
You should read the "Forum Rules" at the top of this board, the third rule of this board is: "Meet the intellectual requirements; We are not to babysit new programmers. Operating system development requires academic thinking and a big deal of knowledge. If you don't have the required knowledge then you should better find a more suitable place to practice."

If you expect people to debug every line of your OS, then it really isn't your OS. Not to mention that most are busy working on their own code. You should aim to become self-sufficient. To do so, I'd recommend getting a copy of "The C Programming Language" 2nd edition. It can easily be read in a weekend, and it is one of the best books on the topic of programming. C is a really thin layer above assembly and is a really good step in learning assembly.

And if you took offense to the way I said my comment, then I apologize. I do not however apologize for the content of my comment. And if you wish to rebuke that then go right ahead, but don't descend into childish insults as a first recourse.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: printing problem

Post by Combuster »

GhostXoPCorp wrote:osdev was made for people who needed help, not for people who have nothing else to do but put retarded things and smart off to people who have just started programming in assembly.
The forum rules explicitly say that OS development is not for newcomers. The forum rules explictly mention a series of things you are required to know.
Your questions are off-topic because the people here are trying to write the most complex pieces of software available, and you expect us experts to teach you the basics.

Experts only put time in people they believe are helped by it. Your inability to solve these basic issues and not knowing a good deal of programming basics (code flow, data structures). If you even start insulting the people who give you a correct answer then I think you need to learn more than some programming skills: respect.

Thread locked and again consider going to an assembly forum.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Locked