So either I'm bad at math or just not understanding how to correctly calculate the memory addresses of a variable.
E.g I got this question right (at least I think so - if not, then I probably picked the answer closest to what I got).
The following data segment starts at memory address 0x1700 (hexadecimal)
.data
printString BYTE "Assembly is fun",0
moreBytes BYTE 19 DUP(0)
dateIssued DWORD ?
dueDate DWORD ?
elapsedTime WORD ?
What is the hexadecimal address of dueDate?
Answer: 0x1727
This one I got wrong
The following data segment starts at memory address 0x1000 (hexadecimal)
.data
printString BYTE "Do not add decimal to hex",0
someBytes WORD 27 DUP(0)
moreBytes BYTE 10, 20, 30, 40, 50, 60, 70, 80, 90
questionAddr DWORD ?
ignoreMe WORD ?
What is the hexadecimal address of questionAddr?
For sure, whatever calculation I come up with, it's either not there or is there but wrong.
Am I suppose to be counting the null terminating byte as part of the length?
addr questionAddr =start addr+sizeof printString +sizeof someBytes +sizeof moreBytes = start addr +59h
Quote from: masterori on March 09, 2016, 04:59:19 PMAm I suppose to be counting the null terminating byte as part of the length?
Not as part of the
length ("string" is 5 bytes long), but as part of
size: db "string", 0 occupies 6 bytes in memory.
someBytes WORD 27 DUP(0) ->how many bytes? The name of this variable is misleading ;)
Quote from: mabdelouahab on March 09, 2016, 05:58:12 PM
addr questionAddr =start addr+sizeof printString +sizeof someBytes +sizeof moreBytes = start addr +59h
So I did that for this problem and got 04B0
.data
list dword 50 dup(?)
matrix dword 20 dup(5 dup(?))
...
Hexadecimal base address of "matrix" is 0x04B0 is what I got since matrixAddr = startAddr + sizeof list = 1000h + 200h = 04B0. But the answer is 10C8. Can you point out what I did wrong?
Why 200h?
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
Inkey "The answer is ", Hex$(1000h+200)
EndOfCode
So I'm a bit confused here, is 1000h = 03E8? or is it actually 1000h? So then, is the 200 from sizeof list = 200h or 0c8? Because 1000 + 0C8 = 10C8 (which is the answer)
Quote from: masterori on March 15, 2016, 05:17:43 PMis the 200 from sizeof list = 200h or 0c8?
200=200
200h=200h
0c8=undefined, no such number format
RTFM.
1000 decimal is 3E8h
windows calculator will make these conversions for you
check the Dec box, put in a value, check the Hex box, the hex value is shown
Hi,
You could let MASM do the counting for you. Create a listing of
your code. Sort of the gold standard result.
HTH,
Steve N.