Sign in to follow this  
tjweb92

Machine code question

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this