News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Hex Numbers

Started by 2-Bit Chip, September 13, 2009, 08:45:27 PM

Previous topic - Next topic

2-Bit Chip

I'm very conscious about putting hexadecimal in my assembly files because I'm always thinking MASM will interpret it as a base-10 and not base-16

[14h] is interpreted as hexadecimal and not base-10?

Could someone clarify this for me?

Astro

I'm reluctant to help you considering your comment in the other thread.

45h = HEX (or 69 in decimal)
45 = DECIMAL (or 0x2D in hex)

Best regards,
Astro.

Slugsnack

by default numbers will be treated as base 10. if you append a h on the end, then it will be treated as base 16. if you want to use hex and your number starts with A-F then you must put 0 before it so the assembler knows it's not a variable name instead

qWord

just for addition: you can change the current default radix with ".radix x" (x=2,8,10,16).
pushcontext radix   ; save current radix. (e.g. this is usefull in context of writing macros)

.radix 16           ; base 16 is now default

    mov eax,0ab     ; 0xAB - no "h"-suffix needed
    mov eax,0123t   ; move decimal value 123 to eax
    mov eax,1101y   ; move binary value 1101 to eax (13 decimal)
   
.radix 2            ; binary numbers
    mov eax,1001    ; move decimal 9 to eax
    mov eax,0abh    ; 0xAB
   
popcontext radix    ; get the orginal radix

FPU in a trice: SmplMath
It's that simple!

2-Bit Chip

Thank you both Slugsnack for the detail (0 infront if it's a letter, ect.) and qWord for the radix. The ".radix" looks interesting :8)

Astro

In addition to radix, you could also write:

mov al, 10010000b ; denotes binary value.

Not sure if other bases are supported this way - haven't tried it.

Quote.radix 16

mov eax,0123t
mov eax,1101y
What's with the 't' and the 'y' ?

Best regards,
Astro.

qWord

"t" ("ten") is the suffix for decimal numbers. "y" or "b" for base 2 ( and "o" for base 8).
I recommend the use of "y", because with "b" you can get into trouble if the default radix is 16 ("b" is an hexdigit)
FPU in a trice: SmplMath
It's that simple!

Astro

Ahh - I see! Suffixes in the context of radix being base 16.

Best regards,
Astro.

hutch--

2-Bit Chip,

You tend to use the numeric format that best fits what you are doing, if the numbers are nothing in particular, decimal is fine and the default, if you are working on addresses HEX is often the most convenient and if you have to mask bits and similar tasks where bit data is useful, you write the complete binary bit form terminated with "b"


Ordinary number 1234
HEX number 0ABCD1234h
BIN number 10101010101010101010101010101010b
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

they use "y" for binary and "t" for decimal whenever the radix is hex because the usual "d" and "b" would be ambiguous