Reputation: 337
List the SHORTEST POSSIBLE CODE (counting number of instructions) for making x, y, and z, defined as follows, get the value 1. for an 80*86 machine
x: dw 0xff00
y: resb 1
z: resw 1
edit: I think the answer should be somethink like that:
MOV DWORD [x+1], 0x01010001 ;
;check:
mov eax , 0
mov al , byte[y]
print_d eax ; print 0
mov eax , 0
mov ax , word[x]
print_d eax ; print 256
mov eax , 0
mov ax , word[z]
print_d eax ; print 257
but. it is not good...sholud print 1
Upvotes: 1
Views: 687
Reputation: 62106
Here's the memory where your x
, y
and z
are, listed as bytes (from lower addresses (x
) to higher (z
)):
xx XX yy zz ZZ
where xx
is the least significant byte of x
(0), XX
is the most significant byte of x
(0xFF) and likewise for y
and z
.
If I understand it correctly, y
and z
aren't initialized (res*
hints NASM syntax for memory reservation keywords).
So you want to transform this:
00 FF yy zz ZZ
into this:
01 00 01 01 00
Right?
MOV DWORD [x+1], 0x01010001
will transform it into:
00 01 00 01 01
So, it's not correct. And you need more than 1 instruction to change 5 bytes because 32-bit instructions write at most 4 bytes at a time.
I'd say the shortest in terms of the number of instructions is 2 MOVs
(NASM syntax):
mov dword [x], 0x01010001
mov byte [x+4], 0
Upvotes: 1