Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Urgent - Print Screen help

3 views
Skip to first unread message

Zhane

unread,
Oct 31, 2009, 11:28:34 PM10/31/09
to

I am able to put values into AL and print using 'CALL PrintCharacter'

but I couldnt print 'msg' with 'Call PrintString'

am I missing anything here? please help


----------------------

cpu 686

use16

segment .text
%define TC_BIOS_KEY_ENTER 1ch

GLOBAL Logger
GLOBAL g_uLoggerCodeSize
GLOBAL g_uCallAskPasswordDeltaOffset

push ax
push es

push ds
pop es ; put ds into es

MOV ESI, msg
Call PrintString

.keypress:
;wait for keypress
mov ah,0
int 16h
pop es
pop ax
.exit:
pop bp
ret ; cdecl

;----------- Procedures --------------

PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL

PUSHA
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on
screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black
background
INT 0x10 ;Call video interrupt
POPA
RET ;Return to calling procedure


; ---- Dont work ----
PrintString: ;Procedure to print string on screen
;Assume that string starting pointer is in register SI

PUSHA
next_character: ;Lable to fetch next character from string
MOV AL, 88 ; X
CALL PrintCharacter

MOV AX, [ESI] ;Get a byte from string and store in AL register
INC ESI ;Increment SI pointer
OR AX, AX ;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL
register
JMP next_character ;Fetch next character from string

exit_function: ;End label
MOV AL, 87 ; W
CALL PrintCharacter

POPA
RET ;Return from procedure

msg dw 'Hello, world!',0xa ;our dear string

Frank Kotler

unread,
Nov 1, 2009, 12:03:48 AM11/1/09
to

Zhane wrote:
> I am able to put values into AL and print using 'CALL PrintCharacter'
>
> but I couldnt print 'msg' with 'Call PrintString'
>
> am I missing anything here? please help
>
>
> ----------------------
>
> cpu 686
>
> use16
>
> segment .text
> %define TC_BIOS_KEY_ENTER 1ch
>
> GLOBAL Logger
> GLOBAL g_uLoggerCodeSize
> GLOBAL g_uCallAskPasswordDeltaOffset

??? Stuff from some other program?

> push ax
> push es
>
> push ds
> pop es ; put ds into es

Where is ds set?

> MOV ESI, msg

Do you really want esi? Appears to be 16-bit code. It'll work...

> Call PrintString
>
> .keypress:
> ;wait for keypress
> mov ah,0
> int 16h
> pop es
> pop ax
> .exit:
> pop bp

??? Looks like a mismatched "pop".

> ret ; cdecl
>
> ;----------- Procedures --------------
>
> PrintCharacter: ;Procedure to print character on screen
> ;Assume that ASCII value is in register AL
>
> PUSHA
> MOV AH, 0x0E ;Tell BIOS that we need to print one charater on
> screen.
> MOV BH, 0x00 ;Page no.
> MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black
> background
> INT 0x10 ;Call video interrupt
> POPA
> RET ;Return to calling procedure
>
>
> ; ---- Dont work ----
> PrintString: ;Procedure to print string on screen
> ;Assume that string starting pointer is in register SI
>
> PUSHA
> next_character: ;Lable to fetch next character from string
> MOV AL, 88 ; X
> CALL PrintCharacter
>
> MOV AX, [ESI] ;Get a byte from string and store in AL register

You want just a single byte in al. (and possibly just si)

> INC ESI ;Increment SI pointer

"lodsb" will "mov al, [si]" and "inc si" in a single instruction

> OR AX, AX ;Check if value in AL is zero (end of string)

Just want al here, too.

> JZ exit_function ;If end then return
> CALL PrintCharacter ;Else print the character which is in AL
> register
> JMP next_character ;Fetch next character from string
>
> exit_function: ;End label
> MOV AL, 87 ; W
> CALL PrintCharacter
>
> POPA
> RET ;Return from procedure
>
> msg dw 'Hello, world!',0xa ;our dear string

"db", not "dw".

... and your string's not zero-terminated...

Is this intended to be a .com file? Need "org 100h", if so (and your
segregs are all set at startup). If it's being linked to an .exe, ds and
es will point to the PSP segment at startup. Since your data is in the
".text" section, start with "push cs"/"pop ds". And "ret" won't exit an
.exe. There may be more... :)

Best,
Frank

Zhane

unread,
Nov 1, 2009, 12:58:42 AM11/1/09
to

On Nov 1, 12:03=A0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
wrote:

> Zhane wrote:
> > I am able to put values into AL and print using 'CALL PrintCharacter'
>
> > but I couldnt print 'msg' with 'Call PrintString'
>
> > am I missing anything here? please help
>
> > ----------------------
>
> > cpu =A0 =A0 =A0 =A0686

>
> > use16
>
> > segment .text
> > %define TC_BIOS_KEY_ENTER 1ch
>
> > GLOBAL =A0 =A0 Logger
> > GLOBAL =A0 =A0 g_uLoggerCodeSize
> > GLOBAL =A0 =A0 g_uCallAskPasswordDeltaOffset

>
> ??? Stuff from some other program?
>
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0ax
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0es
>
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0ds
> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 es =A0 =A0 =A0; put ds into es

>
> Where is ds set?
>
> > MOV ESI, msg
>
> Do you really want esi? Appears to be 16-bit code. It'll work...
>
> > Call PrintString
>
> > .keypress:
> > ;wait for keypress
> > mov ah,0
> > int 16h
> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 es
> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 ax
> > .exit:
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pop =A0 =A0 =A0 =A0bp

>
> ??? Looks like a mismatched "pop".
>
>
>
> > =A0 =A0 =A0 =A0 =A0 =A0ret =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; cd=
ecl
>
> > ;----------- Procedures --------------
>
> > PrintCharacter: =A0 =A0 =A0 =A0 =A0 =A0;Procedure to print character on=
screen
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Assume that ASCII value is in r=
egister AL
>
> > PUSHA
> > =A0 =A0MOV AH, 0x0E =A0 =A0 =A0 =A0 =A0 =A0;Tell BIOS that we need to p=
rint one charater on
> > screen.
> > =A0 =A0MOV BH, 0x00 =A0 =A0 =A0 =A0 =A0 =A0;Page no.
> > =A0 =A0MOV BL, 0x07 =A0 =A0 =A0 =A0 =A0 =A0;Text attribute 0x07 is ligh=
tgrey font on black
> > background
> > =A0 =A0INT 0x10 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Call video interrupt
> > POPA
> > RET =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Return to calling p=

rocedure
>
> > ; ---- Dont work ----
> > PrintString: =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Procedure to print string on =
screen
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Assume that string starting poi=

nter is in register SI
>
> > PUSHA
> > next_character: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Lable to fetch =
next character from string
> > =A0 =A0MOV AL, 88 =A0 =A0 =A0 =A0 =A0 =A0 =A0; X
> > =A0 =A0CALL PrintCharacter
>
> > =A0 =A0MOV AX, [ESI] =A0 =A0 =A0 =A0 =A0 ;Get a byte from string and st=

ore in AL register
>
> You want just a single byte in al. (and possibly just si)
>
> > =A0 =A0INC ESI =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Increment SI pointer

>
> "lodsb" will "mov al, [si]" and "inc si" in a single instruction
>
> > =A0 =A0OR AX, AX =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Check if value in AL is z=

ero (end of string)
>
> Just want al here, too.
>
> > =A0 =A0JZ exit_function =A0 =A0 =A0 =A0;If end then return
> > =A0 =A0CALL PrintCharacter =A0 =A0 ;Else print the character which is i=
n AL
> > register
> > =A0 =A0JMP next_character =A0 =A0 =A0;Fetch next character from string
>
> > exit_function: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;End label
> > =A0 =A0MOV AL, 87 =A0 =A0 =A0 =A0 =A0 =A0 =A0; W
> > =A0 =A0CALL PrintCharacter
>
> > =A0 =A0POPA
> > =A0 =A0RET =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Return from procedu=
re
>
> > msg =A0 =A0 =A0 =A0dw =A0 =A0 =A0'Hello, world!',0xa =A0 =A0 ;our dear =

string
>
> "db", not "dw".
>
> ... and your string's not zero-terminated...
>
> Is this intended to be a .com file? Need "org 100h", if so (and your
> segregs are all set at startup). If it's being linked to an .exe, ds and
> es will point to the PSP segment at startup. Since your data is in the
> ".text" section, start with "push cs"/"pop ds". And "ret" won't exit an
> .exe. There may be more... :)
>
> Best,
> Frank

kind of.
I'm trying to do some print screen so that I know what is it doing

the person gcc -m32 newname file1.o file2.o

this is file2.o

Zhane

unread,
Nov 1, 2009, 12:59:17 AM11/1/09
to

On Nov 1, 12:03=A0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
wrote:
> Zhane wrote:
> > I am able to put values into AL and print using 'CALL PrintCharacter'
>
> > but I couldnt print 'msg' with 'Call PrintString'
>
> > am I missing anything here? please help
>
> > ----------------------
>
> > cpu =A0 =A0 =A0 =A0686

>
> > use16
>
> > segment .text
> > %define TC_BIOS_KEY_ENTER 1ch
>
> > GLOBAL =A0 =A0 Logger
> > GLOBAL =A0 =A0 g_uLoggerCodeSize
> > GLOBAL =A0 =A0 g_uCallAskPasswordDeltaOffset

>
> ??? Stuff from some other program?
>
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0ax
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0es
>
> > =A0 =A0 =A0 =A0 =A0 =A0push =A0 =A0ds
> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 es =A0 =A0 =A0; put ds into es
>
> Where is ds set?

I dont know where is the ds?
the code was supposed to be done with gcc -m32 newname file1.o file2.o
this code will compile into file2.o with nasm -f elf file2.asm

file1.o is essential a C code, which calls something from file2.asm


>
> > MOV ESI, msg
>
> Do you really want esi? Appears to be 16-bit code. It'll work...

I'm puzzled with this too. I started with MOV SI,msg
it can compile on nasm -f elf file2.asm
but when I do gcc -m32 newname file1.o file2.o
I get

relocation truncated to fit: R_386_16 against `.text'
collect2: ld returned 1 exit status


>
> > Call PrintString
>
> > .keypress:
> > ;wait for keypress
> > mov ah,0
> > int 16h

> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 es
> > =A0 =A0 =A0 =A0 =A0 =A0pop =A0 =A0 ax
> > .exit:
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pop =A0 =A0 =A0 =A0bp
>

> ??? Looks like a mismatched "pop".
>
>
>

> > =A0 =A0 =A0 =A0 =A0 =A0ret =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; cd=
ecl
>
> > ;----------- Procedures --------------
>
> > PrintCharacter: =A0 =A0 =A0 =A0 =A0 =A0;Procedure to print character on=
screen
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Assume that ASCII value is in r=
egister AL
>
> > PUSHA
> > =A0 =A0MOV AH, 0x0E =A0 =A0 =A0 =A0 =A0 =A0;Tell BIOS that we need to p=
rint one charater on
> > screen.
> > =A0 =A0MOV BH, 0x00 =A0 =A0 =A0 =A0 =A0 =A0;Page no.
> > =A0 =A0MOV BL, 0x07 =A0 =A0 =A0 =A0 =A0 =A0;Text attribute 0x07 is ligh=
tgrey font on black
> > background

> > =A0 =A0INT 0x10 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Call video interrupt
> > POPA


> > RET =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Return to calling p=
rocedure
>

> > ; ---- Dont work ----


> > PrintString: =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Procedure to print string on =
screen
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Assume that string starting poi=

nter is in register SI
>
> > PUSHA

> > next_character: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0;Lable to fetch =
next character from string
> > =A0 =A0MOV AL, 88 =A0 =A0 =A0 =A0 =A0 =A0 =A0; X
> > =A0 =A0CALL PrintCharacter
>

> > =A0 =A0MOV AX, [ESI] =A0 =A0 =A0 =A0 =A0 ;Get a byte from string and st=


ore in AL register
>
> You want just a single byte in al. (and possibly just si)
>

> > =A0 =A0INC ESI =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Increment SI pointer


>
> "lodsb" will "mov al, [si]" and "inc si" in a single instruction
>

> > =A0 =A0OR AX, AX =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Check if value in AL is z=


ero (end of string)
>
> Just want al here, too.
>

> > =A0 =A0JZ exit_function =A0 =A0 =A0 =A0;If end then return
> > =A0 =A0CALL PrintCharacter =A0 =A0 ;Else print the character which is i=
n AL
> > register
> > =A0 =A0JMP next_character =A0 =A0 =A0;Fetch next character from string
>
> > exit_function: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;End label
> > =A0 =A0MOV AL, 87 =A0 =A0 =A0 =A0 =A0 =A0 =A0; W
> > =A0 =A0CALL PrintCharacter
>
> > =A0 =A0POPA
> > =A0 =A0RET =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;Return from procedu=
re
>
> > msg =A0 =A0 =A0 =A0dw =A0 =A0 =A0'Hello, world!',0xa =A0 =A0 ;our dear =

string
>
> "db", not "dw".
>
> ... and your string's not zero-terminated...
>
> Is this intended to be a .com file? Need "org 100h", if so (and your
> segregs are all set at startup). If it's being linked to an .exe, ds and
> es will point to the PSP segment at startup. Since your data is in the
> ".text" section, start with "push cs"/"pop ds". And "ret" won't exit an
> .exe. There may be more... :)
>
> Best,
> Frank

I had all u suggested initially, but cause of the relocation error
from NASM, I decided to try something else

you mean do push cs, pop ds before i Mov si, msg?


Frank Kotler

unread,
Nov 1, 2009, 1:37:57 AM11/1/09
to

Zhane wrote:
> On Nov 1, 12:03=A0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
> wrote:
>> Zhane wrote:
>>> I am able to put values into AL and print using 'CALL PrintCharacter'
...

> the code was supposed to be done with gcc -m32 newname file1.o file2.o
> this code will compile into file2.o with nasm -f elf file2.asm
>
> file1.o is essential a C code, which calls something from file2.asm

Wait a minute. You're telling me that you printed a character using int
10h in Linux? I find that hard to believe. If that's really true, I
wanna see file1!!!

If you want a "PrintCharacter" for Linux, callable from C, that can be
arranged. But int 10h isn't going to work without jumping through some
extraordinary hoops!

Tell us more about what you're trying to do, Zhane.

Best,
Frank

Zhane

unread,
Nov 1, 2009, 8:56:18 AM11/1/09
to

On Nov 1, 1:37=A0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
wrote:
> Zhane wrote:
> > On Nov 1, 12:03=3DA0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.co=

m>
> > wrote:
> >> Zhane wrote:
> >>> I am able to put values into AL and print using 'CALL PrintCharacter'
> ...
> > the code was supposed to be done with gcc -m32 newname file1.o file2.o
> > this code will compile into file2.o with nasm -f elf file2.asm
>
> > file1.o is essential a C code, which calls something from file2.asm
>
> Wait a minute. You're telling me that you printed a character using int
> 10h in Linux? I find that hard to believe. If that's really true, I
> wanna see file1!!!
>
> If you want a "PrintCharacter" for Linux, callable from C, that can be
> arranged. But int 10h isn't going to work without jumping through some
> extraordinary hoops!
>
> Tell us more about what you're trying to do, Zhane.
>
> Best,
> Frank

hmm
isnt Int 13h and int 10h going to work?
i tried on vm, and it did print something for me

Frank Kotler

unread,
Nov 1, 2009, 11:51:31 AM11/1/09
to

Zhane wrote:
> On Nov 1, 1:37=A0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
> wrote:
>> Zhane wrote:
>>> On Nov 1, 12:03=3DA0pm, Frank Kotler <fbkot...@MUNGED.microcosmotalk.co=
> m>
>>> wrote:
>>>> Zhane wrote:
>>>>> I am able to put values into AL and print using 'CALL PrintCharacter'
>> ...
>>> the code was supposed to be done with gcc -m32 newname file1.o file2.o
>>> this code will compile into file2.o with nasm -f elf file2.asm
>>> file1.o is essential a C code, which calls something from file2.asm
>> Wait a minute. You're telling me that you printed a character using int
>> 10h in Linux? I find that hard to believe. If that's really true, I
>> wanna see file1!!!
>>
>> If you want a "PrintCharacter" for Linux, callable from C, that can be
>> arranged. But int 10h isn't going to work without jumping through some
>> extraordinary hoops!
>>
>> Tell us more about what you're trying to do, Zhane.
>>
>> Best,
>> Frank
>
> hmm
> isnt Int 13h and int 10h going to work?

Not ordinarily - 16-bit code.

> i tried on vm, and it did print something for me

Well, vm maybe. There *are* kernel services for it, vm86old (113) and
vm86 (166). I've never had any luck with 'em (didn't try too hard) -
dosemu does it. I really want to see your "file1"! Does it use LRMI?

I've got some notes that "Richard Cooper" (aka "PJ" and some other names
- author of "softer") posted to the linux-assembly list. I'll post that,
if it's really what you want to do. Be *very* careful writing anything
with int 13h, if you're going to attempt that!!! Int 10h should be
"mostly harmless".

I tried an "experiment" with this (can't find it now) which didn't work,
but IIRC it *did* return an error code consistent with it "almost
working". If your code gets as far as printing a character, we can
probably get PrintString working, with some experimentation...

If your "file1" (.c I presume?) is available on the web, send us a link
to it. It's probably too long to post here(?). You can send it to me -
fbko...@myfairpoint.net if you're willing.

This could be a very interesting project!

Best,
Frank

Jim Carlock

unread,
Nov 4, 2009, 3:30:45 PM11/4/09
to

"Frank Kotler" <fbko...@munged.myfairpoint.net> wrote...
: If your "file1" (.c I presume?) is available on the web, send us a

: link to it. It's probably too long to post here(?). You can send it
: to me - fbko...@munged.myfairpoint.net if you're willing.

:
: This could be a very interesting project!

I am interested in this as well. Did he send you any more details at
all?

--
Jim Carlock

Frank Kotler

unread,
Nov 4, 2009, 3:39:33 PM11/4/09
to

Nope. I'm beginning to think I'm confused about what he's trying to do,
and what worked. I took another look at LRMI (SourceForge), and I don't
think that's it. I guess maybe it wasn't all that urgent...

Best,
Frank


Zhane

unread,
Nov 7, 2009, 1:51:13 AM11/7/09
to

On Nov 5, 4:39=A0am, Frank Kotler <fbkot...@MUNGED.microcosmotalk.com>
wrote:
> Jim Carlock wrote:
> > "Frank Kotler" <fbkot...@munged.myfairpoint.net> wrote...

> > : If your "file1" (.c I presume?) is available on the web, send us a
> > : link to it. It's probably too long to post here(?). You can send it
> > : to me - fbkot...@munged.myfairpoint.net if you're willing.

> > :
> > : This could be a very interesting project!
>
> > I am interested in this as well. Did he send you any more details at
> > all?
>
> Nope. I'm beginning to think I'm confused about what he's trying to do,
> and what worked. I took another look at LRMI (SourceForge), and I don't
> think that's it. I guess maybe it wasn't all that urgent...
>
> Best,
> Frank

I was busy over the week. It still isnt wroking :S

0 new messages