x86 - Displaying symbolic constants in Assembly Language -
assuming printstring user defined function prints null terminated string, why wouldn't following code print value of symbolic constant secondsinday
? other corrections in code highly welcomed.
.data secondsinday = 60*60*24 textstr textequ <secondsinday> .code main proc call clrscr mov edx,offset secondsinday ; or mov edx,offset textstr call printstring exit main endp end main
presumably printstring function expects edx contain address, 1 points location in memory characters make string printed stored. since you've assigned secondsinday number, instruction mov edx,offset secondsinday
loads edx register number. not address of number, nor address of string containing decimal representation of number. since 86400 not valid address, printstring crash. since textstr text equate contains sequence of characters, not valid address.
if want print out number of seconds in day printstring you'll first have allocate storage characters make string:
.data secondsindaystr db '86400', 0 ; zero-terminated c-style string
this both provides location in memory string , assigns secondindaysstr address of location. can print out printstring:
mov edx, offset secondsindaystr call printstring
note symbols things assembler (and maybe linker , debugger) know about. time program runs symbols used instructions in code have been replaced actual value. symbols addresses (eg. symbol main
in program) neither secondsinday nor textstr addresses.
Comments
Post a Comment