English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 12 August 2016, 01:29   #1
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 399
Help with VPrintf

Hi I'm trying to work out how to use VPrintf.

Here's my program and I want it to output 45 but instead it is outputting 133659

****
Include exec/types.i
include exec/libraries.i
Include exec/exec_lib.i
include dos/dos_lib.i
Include macros.i

start:
lea dos_name(pc),a1
CALLEXEC OpenLibrary
move.l d0,dosbase
beq.s exit

print_text:
move.l #format_text,d1
move.l #text,d2
CALLSYS VPrintf,dosbase

exit:
move.l dosbase,a1
CALLEXEC CloseLibrary
rts

dos_name:
dc.b 'dos.library',0

dosbase:
ds.l

format_text:
dc.b '%1d',0

text:
dc.b '45',0
Nightfox is offline  
Old 12 August 2016, 01:31   #2
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 399
Ugh my code In the post lost its formatting.
Nightfox is offline  
Old 12 August 2016, 01:50   #3
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by sacredbanana View Post
Hi I'm trying to work out how to use VPrintf.

Here's my program and I want it to output 45 but instead it is outputting 133659
Are you sure it is not 13365 that it is outputting? The ASCII for '4' = $34 and '5' = $35 so consecutively would be $3435=13365. If that was not enough of a hint, try changing the following.

Code:
text:
   dc.b '45',0
to

Code:
text:
   dc.l 45
You might want a new name for that text label if I'm right though .
matthey is offline  
Old 12 August 2016, 02:51   #4
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 399
Thank you yes there was a typo in what it output. I understand now that it is actually outputting the decimal values of the ascii for each character in the string. Your hint outputs a 0. I'm still confused as to how I can fix this... and I recently graduated with a degree in computer science haha. This is my first time with assembly.
Nightfox is offline  
Old 12 August 2016, 03:10   #5
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by sacredbanana View Post
Thank you yes there was a typo in what it output. I understand now that it is actually outputting the decimal values of the ascii for each character in the string. Your hint outputs a 0. I'm still confused as to how I can fix this... and I recently graduated with a degree in computer science haha. This is my first time with assembly.
Ok, try the following.

Code:
text:
   dc.w 45,0
Your "%ld" looks like a "%1d" which may be interpreted as "%d". The data being pointed to is a long though.
matthey is offline  
Old 12 August 2016, 03:51   #6
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,844
Quote:
Originally Posted by sacredbanana View Post
Ugh my code In the post lost its formatting.
Put your code between code tags.

<code>
bla
bla
</code>

Just change <> to [].
Thorham is offline  
Old 12 August 2016, 03:55   #7
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 399
I tried that and it wouldn't work and I was pulling my hair out and then I thought maybe the text needs aligning... so I wrote even above the text label and voila it works! Thanks for your help
Nightfox is offline  
Old 12 August 2016, 16:41   #8
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 722
Also it won't work at all if you pass a really long parameter on cli (~50 chars)
and it will probably crash cause exit shouldn't close the library (cause the first reason it's at exit was that it couldn't open the library).

PS: The reason that it won't work is you forgot to specify contents of d0 and upon entry a0 points to the cli parameter string and d0 holds the length of that.
alkis is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:38.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07675 seconds with 14 queries