• Advertisement
Sign in to follow this  

Machine code question

This topic is 4233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am creating a new language and am using my compiler to translate my language into machine code. I know allot but can't figgure out how to print to the screen. Does anyone know how to do this.

Share this post


Link to post
Share on other sites
Advertisement
You can't figure out how to print to the screen?

As in, you don't know the assembly required to print to the screen?

Well, as far as I know, that would include getting access to the video buffer, and editing that directly. I recommend that you use C, or another language as the backend to your language.

It would also probably be easier to just create a small scripting language instead of a full-blown compiled to machine code language.

Anyway, that being said, good luck.

Share this post


Link to post
Share on other sites
That depends a lot on the platform. What system and what OS are you expecting your programs to run under?

Share this post


Link to post
Share on other sites
Assuming win32/x86...

You can try int21 (iirc).

ie

stack SEGMENT PARA STACK 'STACK'
DB 64 DUP('STACK ')
stack ENDS
;
dseg SEGMENT PARA PUBLIC 'DATA'
greet DB 'Hello, world!$'
dseg ENDS
;
cseg SEGMENT PARA PUBLIC 'CODE'
start PROC FAR
ASSUME CS:CSEG,DS:DSEG,SS:STACK,ES:NOTHING
mov ax,dseg
mov ds,ax
mov dx,OFFSET greet
mov ah,09H
int 21H
mov ah,4CH
int 21H
start ENDP
cseg ENDS
END start


or so.

Share this post


Link to post
Share on other sites
Without DOS's interrupt 21h, you could write directly to address: 0xB8000.

Example (untested, dunno if it will build, NASM syntax):

mov ebx, 0xB8000
mov es, ebx
mov [es:0], 'L' ;write the letter L to the upper left of the screen




Note that every other byte represents an ASCII character. The bytes in-between are 'attributes' (for color and blinking.)

My recommendation to you is to make your compiler more cross-platform by linking your output object files to C standard libraries (or base your own libraries around them.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement