Code: Select all
inc byte [ErrorValue]
Code: Select all
%define ErrorValue bp + bp_size + (ErrorValuePTR - 7C00h)
Code: Select all
show_error_LE: call Print
db 'Error '
ErrorValuePTR: db '1',0
Zo result of the calculation of ErrorValue is 79h
This value is small enough, to generate one byte less code:
inc byte [bp+79h] is 3 bytes of code.
inc byte [bp+bigvalue] or inc byte [value] is 4 bytes of code.
The problem is Nasm generates 4 bytes of code. When I define ErrorValue manually with value 79h, everything is fine, I get the shorter code.
When I replace (ErrorValuePTR - 7C00h) with 59h, everything is also fine.
Code: Select all
%define ErrorValue bp + bp_size + (ErrorValuePTR - 7C00h)
Code: Select all
%define ErrorValue bp + bp_size + 59h ; (ErrorValuePTR - 7C00h) replaced
I prefer to use ErrorValue and definition with ErrorValuePTR because the address of the address of ErrorValuePTR can change a little bit (but within reach of bp-7fh and bp+7fh)
How can Nasm understand that my definition can use the smaller code?