I am trying to figure out how 12345 in decimal produces 0x39 0x30 in hex. Can anyone explain this? It has been a while since intro to assembly. The suggested posts helped me a bit, but none have an example that illustrates how this works.
.hword 0xAA55, 12345 ; inserts the bytes 0x55 0xAA 0x39 0x30
Given hword deals with 16 bits at a time, how does 12345 give the hex result stated?
Would the values be the same for a 64bit? Just padded with 0xFF?
@dwelch - Thank you so much.
what does assembly language have to do with any of this? nothing.
127 seconds is how many minutes? How do you figure that out? 60 seconds per minute right? so 127/60 = 2.116666.... right? or 2 remainder 7, 127 seconds is 2 minutes 7 seconds.
4000 seconds is how many hours, minutes, seconds? well 60 seconds per minute and 60 minutes per hour so 3600 seconds per hour, start with the largest placeholder, 4000/3600 is 1 remainder 400, so 1 hour 400 seconds. 400 seconds / 60 is 6 remainder 40. so 4000 seconds is 1 hour 6 minutes and 40 seconds.
We learned how to do that in grade school yes? conversion from decimal to base 60. How is that any different from decimal to base 16? it isnt.
note ones position is 10 to the power 0, tens position is 10 to the power 1, hundreds 10 to the power 2 and so on. seconds is 60 to the power 0, minutes position is 60 to the power 1 and hours position is 60 to the power 2.
12345 decimal. what are our base 16 placeholders? 16 to the power 0 is 1, 16 to the power 1 is 16, 16 to the power 2 is 256, 16 to the power 3 is 4096, 16 to the power 4 is 65536. 12345 is less than 65536 and more than 4096 so we start there, 12345/4096 = 3 remainder 57. so that is 16 to the power 3 position or 0x3xxx. 57/256 = 0 remainder 57 so 0x30xx. 57/16 = 3 remainder 9 so 12345d = 0x3039.
then the arm is little endian so that byteswaps to 0x39,0x30 in memory.