🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.linux.development.apps
5 messages
5 total messages Started by Meir Dukhan Sun, 21 Apr 1996 11:50
Assembler Statement in C program
#13
Author: Meir Dukhan
Date: Sun, 21 Apr 1996 11:50
38 lines
1181 bytes
Hi, 

I'm trying to port some piece of C code to linux/unix.
This code contains statement in assembler.

1. How can I compile it under linux with gcc or gas ?

2. Will this be portable ?

example:

static void clear_screen(void)
{
    _asm
     {
         mov   ax,40h
         mov   es,ax
         mov   ax,0600h
         mov   bx,0700h
         mov   cx,0
         mov   dl, es:byte ptr[4ah]
         dec   dl
         mov   dh, es:byte ptr[84h]
         or    dh,dh
         jnz   k1
         mov   dh,24
k1:
         int   10h
         mov   dx,0
         mov   ax,0200h
         mov   bx,0
         int   10h
     }
}


-- 
		Meir
Re: Assembler Statement in C program
#16
Author: smryan
Date: Sun, 21 Apr 1996 12:37
27 lines
1679 bytes
: I'm trying to port some piece of C code to linux/unix.
: This code contains statement in assembler.

: 1. How can I compile it under linux with gcc or gas ?

I have no idea.

: 2. Will this be portable ?

Only to other DOS machines.

If you're running X-Windows on an x86, you don't want to use BIOS to
clear the screen; and if it's called BIOS on a Sparc, it is a very
different (though forthright) BIOS.

Although the concept is portable, no implementation is, so you'll have
to do something specific for the system and display. For example, if
you're doing X-Windows, you can clear a window with X calls, or with
curses if it xwsh, or something of that ilk. On a Mac, you set up the
clipping region and fill it. On a glass tty, you can you curses or look
up the terminal clear screen code (or send a few dozen new lines).

-- 
The Queen who loves, the Queen of life,    | smryan@netcom.com  PO Box 1563
the Queen who straits, the Queen of strife;|          Cupertino, California
with gasp of death or gift of breath       | (xxx)xxx-xxxx            95015
she brings the choice of birth or knife.   |         I don't use no smileys
Re: Assembler Statement in C program
#14
Author: Roger Espel Llima
Date: Sun, 21 Apr 1996 14:00
54 lines
2957 bytes
In article <317A2105.77EF485@bis.co.il>, Meir Dukhan  <meir@bis.co.il> wrote:
>Hi, 
>
>I'm trying to port some piece of C code to linux/unix.
>This code contains statement in assembler.
>
>1. How can I compile it under linux with gcc or gas ?
>
>2. Will this be portable ?

[ code snipped ]

There are various problems with that; one is that your code is 8086 
assembler, which runs unmodified on 386+ processors only when they are 
in "real mode".  However, Linux runs in protected mode, which is much 
more powerful but not compatible.  Also, your code accesses some 
absolute memory addresses and calls BIOS interrupts, which Linux won't 
let you do (because of memory protection and security, as well as 
different addressing).  Thirdly, none of this would be portable to any 
other Unix system.

Porting programs from DOS to Unix isn't that easy if they interact 
directly with the system and/or do any kind of full-screen handling;
to do this properly in Unix (and Linux), you can do either of these:

 . use the 'ncurses' library, which is a portable and powerful package 
 of full-screen handling routines.  Check out the manual page for it,
 with "man ncurses".

 . use the termcap interface, which is portable but much less of a 
 powerful library.  it might actually be easier to you if you're used
 to low-level handling in DOS, as this is pretty low-level too.
 Check out the man pages for 'termcap'.  Under some Linux versions this 
 is in fact emulated by the ncurses library, and documented in the
 man page for 'curs_termcap'.  Also, this won't handle the tty mode
 (keyboard input mode) for you, so check out the manpage for 
 'tcgetattr' and 'tcsetattr'.

 . if you're only going to be using your program on the Linux console
 and other ANSI-compatible terminals, directly use the ANSI escape 
 sequences to do things like clear the screen.  As far as I know they're 
 not on any man page on Linux.  You'll also need to deal with 
 tcgetattr() and tcsetattr() yourself.  It's not portable to general
 terminals.

Mail me if you want some sample code that uses the 2nd alternative.

	-Roger
--
#!/usr/local/bin/perl                       # e-mail: roger.espel.llima@ens.fr
s**QJwEw=QGv:vt=PGwEvvvEwt=OGUtMGUt=N\@:tKG:A=O> G:GNb,&+ 1%" Z)2" j&zz,+ Y+1*
,s^$^&E["+0,/0%&- [y*-y&\$+!=Pt:S=QtUSQM%11-RGG444F"##F,/\$Gz)2"/&zz,+F%1*)=^,
s@$@Q SF=QSUUt=PSF:t=OSJ>=NSL>PN/,\$"/F"0-")F))&*yX"+0F#/=NtUUGNtUUG=OtGPtG=@,
y,= :-|"-9,\n "-|, ,s,&,\\"\\,g,s,;,/"/,g,s,",===,g,s,(\d),' 'x$1,eg,print $_;
Re: Assembler Statement in C program
#15
Author: Kazimir Kylheku
Date: Sun, 21 Apr 1996 14:40
94 lines
3465 bytes
In article <317A2105.77EF485@bis.co.il>, Meir Dukhan  <meir@bis.co.il> wrote:
>Hi, 
>
>I'm trying to port some piece of C code to linux/unix.
>This code contains statement in assembler.
>
>1. How can I compile it under linux with gcc or gas ?

You can't. It's not 32-bit code. GAS compiles 32-bit assembly language, and the
instruction format is different from what the assemblers use under DOS.
You should rewrite the code to conform.

>2. Will this be portable ?

Of course not. It's assembly language. A machine that doesn't share the same
assembly language instruction set will not be able to make use of the code
without some sort of translation or emulation, which defeats the purpose of
coding in assembly in the first place.

>example:
>
>static void clear_screen(void)
>{
>    _asm
>     {
>         mov   ax,40h
>         mov   es,ax
>         mov   ax,0600h
>         mov   bx,0700h
>         mov   cx,0
>         mov   dl, es:byte ptr[4ah]
>         dec   dl
>         mov   dh, es:byte ptr[84h]
>         or    dh,dh
>         jnz   k1
>         mov   dh,24
>k1:
>         int   10h
>         mov   dx,0
>         mov   ax,0200h
>         mov   bx,0
>         int   10h
>     }
>}

You are making software interrupt calls to 16-bit bios here, which make no
sense in any environment other than DOS. Also the area at segment 040H is
unique to DOS. This has no hope of being portable to anything other than DOS,
or systems that emulate DOS/BIOS functionality.

This is the most inane use of assembly language I have seen, considering that
DOS compilers have the _int86() primitive for dealing with BIOS calls, not to
mention <conio.h> screen functions for simple tasks like clearing the screen,
positioning the cursor and the like.

It could all be done with existing, documented interfaces (however non standard
they some of them may be).

Linux does not use direct screen writes to manage the screen, and it doesn't
have a concept of an addressable screen area. You clear the screen by sending
the appropriate control code to the terminal device. This method works on local
consoles as well as remote terminals, or terminal emulator windows alike.

Learn how to use the curses library to do full-screen manipulation and
character input on terminals. There are curses ports to DOS, so as an added
benefit, your curses-based programs can be ported back to DOS.  

I'll give you a hint:

#include <stdio.h>
#include <curses.h>

int main()

{
	initscr();		/* initialize curses			*/
	noecho();		/* disable echo				*/
	cbreak();		/* disable input line processing	*/

	/* put hello message at row 5, column 10 (home is 0,0)		*/

	mvprintw(4, 9, "Hello, world!");

	refresh();	/* update terminal	*/
	getch();	/* wait for keystroke	*/
	erase();	/* erase screen		*/
	refresh();	/* update terminal	*/
	getch();	/* wait for another key	*/
	refresh();	/* update		*/

	endwin();	/* stop curses		*/

	return 0;
}
Re: Assembler Statement in C program
#17
Author: Arcadio A. Sincero Jr.
Date: Sun, 21 Apr 1996 20:40
26 lines
1683 bytes
	I personally have found John E. Davis' SLang library a whole lot
easier to use than NCurses.  It may not be as robust as NCurses, but it sure
is a whole lot easier to use.  Plus, from what I hear, it's faster too. 
Plus, in addition to it's screen handling functions, it's also got keyboard
handling and some kind of cool built-in interpreted language that I really
haven't figured out what to do with yet.  

	So get SLang instead from ftp://space.mit.edu/pub/davis/slang. 
Documentation is kinda sketchy 'tho, but it suffices.  ('tho it seems the
docs were written for an earlier version of SLang 'cause when I check out
the SLang header file, I see references to functions not mentioned in the
docs.).

	One other thing, there are versions of SLang for DOS, OS/2, and
a bunch of Unices, including Linux (of course).


-- 
===============================================================================
Arcadio Alivio Sincero, Jr.
Sophomore, Computer Science Major at the University of Maryland at College Park
Amateur competitive bodybuilder
Email: lotu@wam.umd.edu, WWW: http://www.wam.umd.edu/~lotu

"D.A.R.E. .... to keep cops of donuts."
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads