🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.development.apps
Article #15

Re: Assembler Statement in C program

#15
From: 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;
}
Technical Details
Message-ID: <4ldhctINNmdj@keats.ugrad.cs.ubc.ca>
Path: arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mail
References: <317A2105.77EF485@bis.co.il>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mail
From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
Newsgroups: comp.os.linux.development.apps,comp.unix.programmer,comp.lang.c
Subject: Re: Assembler Statement in C program
Date: 21 Apr 1996 07:40:29 -0700
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Message-ID: <4ldhctINNmdj@keats.ugrad.cs.ubc.ca>
References: <317A2105.77EF485@bis.co.il>
NNTP-Posting-Host: keats.ugrad.cs.ubc.ca