[A86] Re: Using hex values in strings?


[Prev][Next][Index][Thread]

[A86] Re: Using hex values in strings?



> Huh?  The format string is always going to be the same: "%s".  I'll assume
> you want to actually want to print the base-10 exponent E symbol and are
> having trouble.
> using zcc +ti86 -v -startup=10
>
>    char c = '\x1b';
>    putchar (c);
>
> works for me, as does
>
>    const char *s = "1.2\x1b5";
>    puts (s);
>
> as does
>
>    const char *s = "1.2\x1b5";
>    printf ("%s",s);
>
> The output for the last two is "1.2E5".  Not quite sure what you were
> doing.

I was writing a test input routine to get a feel for using the z88dk.  Using
the format string "%s" would dump some given amount of memory, since 0x1B
doesn't have a null terminator attached.  Using "%c" fixed the problem.
Using the above method of embedding the character in the string would have
worked, had I known it.  On x86 systems, you don't normall have to enter
characters as hex. ;)
>
> >>   I'm using the z88dk cross-compiler to develop an ASM program, being
> >> reasonably proficient at C and only enough to understand what is
>     ^^^  hmm.
>
> Then again, we could give you your first lesson in asm just to show how
> easy it is.
>
> #include "ti86asm.inc"          ;   ROM, RAM, character and key equates
> .org            _asm_exec_ram
>          ld      hl,str
>          call    _puts
>          ret
> str:    .db     "1.2",Lexponent,"5",0
> .end
>
> (again, output is "1.2E5").
>

I don't particularly want to write out four or five lines of assembly for
each line of C code (normally).  Besides, if I see any major memory waste
going on (printf for example, at ~1K) I'll rewrite the appropriate function
in assembly and use it instead.

Andy





Follow-Ups: References: