Reputation: 51
So I can't figure out why my program doesn't work and the different outputs for different input. I have 2 variables:
static_num1_ptr dw 7 ;
static_num1_ptr_ptr dw [static_num1_ptr];
I have this code:
mov bx,static_num1_ptr_ptr;
mov bx,[bx];
mov ax,[bx];
call print_num
I need to change the declaration of the num1-ptr and num1_ptr_ptr in order to print 7. I can't change the 4 lines of code. I tried changing num1_ptr_ptr to be equal to [num1_ptr] and num1_ptr to be 7. But that gives me 0. Can someone help me understand the logic here? I use emu8086
Upvotes: 2
Views: 526
Reputation: 9899
I can't change the 4 lines of code.
I think the solution lies in closely reading the names of these labels!
If the first label reads static_num1_ptr, it most probably means that it is supposed to be a pointer to num1 and not the value of num1 itself.
You'll need a third line here:
static_num1 dw 7
static_num1_ptr dw offset static_num1
static_num1_ptr_ptr dw offset static_num1_ptr
Now your 4 lines of code
mov bx, static_num1_ptr_ptr
mov bx, [bx]
mov ax, [bx]
call print_num
will correctly dereference twice ([bx]
) and print the value 7.
Upvotes: 3