*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.
printing problem
Re: printing problem
See my earlier post about some BIOSes trashing your registers...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?
Re: printing problem
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:
-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
Re: printing problem
well
first:
is perfect
except from the real problem
this is what the CPU sees, when it start to run your program:
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:
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
first:
Code: Select all
org 100h
use16
hello db 'Hello',0
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
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
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.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
Re: printing problem
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.
Re: printing problem
A pm from Ghost:
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.
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.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?
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."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.
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.
- Combuster
- 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
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.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.
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.