C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-08-2001, 06:03 AM   #1
Wavering
Guest
 
Posts: n/a
Inline ASM and Screen Clearing

Have just started teaching myself C and thought the following may be useful to fellow strugglers!
They use inline asm to print messages and also clear the screen in one line with system("cls")
There are no header files needed ie no <stdio.h> stuff

/* test01.c Shows using _asm to print message ( See Test02.c for arrays */
main()
{
char *namer = "Hello, world pointers! $";
system("cls"); //Clear Screen
_asm
{
mov dx, namer ; ";" is for comments
mov ah,09h
int 21h ;A DOS interrupt
}
}

/* test02.c Access contents of an array using _asm */
main()
{
char name[20] = "Hello, double pointers! $";
char *dummy = name;
/* So dummy contains the address of pointer */
_asm
{
mov dx, byte ptr dummy
;The above is tricky - it moves the address
;of dummy into dx for the DOS interrupt
mov ah,09h
int 21h
}
}

THE FOLLOWING DOES NOT WORK

/* DOES NOT WORK ( See Test 01 & Test02 for ones that work ) */
main()
{
char name[30] = "Hello, world fails! $";
_asm
{
mov dx, name
mov ah,09h
int 21h
}
}

I think it fails because although "name" is the pointer to name[30] it is a kind of hybrid as far as asm is concerned ( or something ) If you run this program you will find it ploughs through huge amounts of memory and finally prints garbage ending with Hello, world fails! So it sort of works ...
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASM With C Programming peckitt99 C Programming 11 10-28-2006 01:40 PM
How Can I.....(OpenGL) Shamino Game Programming 33 06-01-2005 06:31 AM
Inline ASM with SDL Graphics (Not same as C/C++ coding result) ... :( SyntaxBubble Game Programming 6 10-15-2003 09:00 PM
Calling Class Functions in ASM? SyntaxBubble Windows Programming 2 10-14-2003 12:48 AM
need help in making graphics in C++ Unregistered A Brief History of Cprogramming.com 10 10-21-2001 12:14 PM


All times are GMT -6. The time now is 10:41 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22