1

I'm using the SASM IDE using NASM as my assembler to produce a 32-bit program. How can I know the number of bytes (first parameter) I need for a given input when using the PRINT_DEC macro? let's say I need to print 6518846, how many bytes do I need to declare for the size? I think this is why my program prints out the wrong data, it is out of range.

Once I exceed some numbers, it starts giving negative outputs.

the code below prints out "32767" perfectly. but if I changed it to 32768 or higher, the output changes into a negative one.

%include "io.inc"

section .text
global CMAIN
CMAIN:

PRINT_DEC 1, 32767

xor eax, eax
ret
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
ae winter
  • 11
  • 2
  • 1
    SASM is an IDE, not a language or an assembler. It isn't clear what you mean by "how many bytes". If you have an issue with your code, you need to post a [mre]. – interjay Feb 27 '23 at 10:40
  • @interjay, sorry i've fixed it now. – ae winter Feb 27 '23 at 10:47
  • That's because presumably `PRINT_DEC` takes a 16 bit signed value. Check whether you have unsigned and/or 32 bit function. – Jester Feb 27 '23 at 11:11
  • You can use `PRINT_UDEC` to print as unsigned values. Rather than a size of 1 (size is the first parameter) you can use a size of 4 to print out values up to 2^32-1. – Michael Petch Feb 27 '23 at 11:27
  • If the first parameter is the size in bytes, you'd need 2 to print 32767, not 1 as shown. – interjay Feb 27 '23 at 11:37
  • 1
    When using `PRINT_DEC` (signed integers) with a constant value a size of 1 or 2 has a range of -2^15 to +2^15-1. A size of 4 allows -2^31 to +2^31-1 and with x86-64 a size of 8 is -2^63 to +2^63-1. When using `PRINT_UDEC` (unsigned integers) with a constant value a size of 1 or 2 has a range of 0 to +2^16-1. A size of 4 allows 0 to +2^32-1 and with x86-64 a size of 8 is 0 to +2^64-1. – Michael Petch Feb 27 '23 at 12:02

0 Answers0