News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Question on how to approach two seperate problems

Started by tntsgoboom, February 11, 2016, 02:57:02 PM

Previous topic - Next topic

tntsgoboom

Hey guys,
   I have an exam coming up. While reviewing some of my summary questions I noticed I continue to get the same two types of problems wrong. I was hoping someone could explain to me how to go about getting the correct answer for each. Here is an example of the first:

The following data segment starts at memory address 0x2300 (hexadecimal)
.data
printString BYTE "Assembly is fun",0
moreBytes BYTE 48 DUP(0)
dateIssued DWORD ?
dueDate DWORD ?
elapsedTime WORD ?

What is the hexadecimal address of dueDate?

What should I be doing to get the correct answer here?


The other question I have:

The four-byte sequence 0xA0 0x8C 0x8C 0x6B stored in consecutive memory cells in a little-endian architecture represents ___________ (decimal) when interpreted as a 32-bit signed integer.

Any help is really appreciated thanks again!

jj2007

0x2300
+sizeof "Assembly is fun",0
+sizeof moreBytes
+4 bytes dateIssued
=?

0xA0 0x8C 0x8C 0x6B as bytes
0x6B8C8CA0 as dword (least significant byte at last position)

dedndave


K_F

The following data segment starts at memory address 0x2300 (hexadecimal)
.data
printString BYTE "Assembly is fun",0      === (0x10) 16 bytes (including the end zero)
moreBytes BYTE 48 DUP(0)                    === (0x30) 48 bytes
dateIssued DWORD ?                            === (0x04) 4 bytes
dueDate DWORD ?                                === (0x04) 4 bytes
elapsedTime WORD ?                            === (0x02) 2 bytes

What is the hexadecimal address of dueDate?   === 0x2300 + 0x10 + 0x30 + 0x04  = 0x2344 (you don't include the dueDate size)

The other question I have:
The four-byte sequence 0xA0 0x8C 0x8C 0x6B stored in consecutive memory cells in a little-endian architecture represents  === 0x6B 8C 8C A0 ( just convert this to decimal with the normal methods)
The four-byte sequence 0xA0 0x8C 0x8C 0x6B stored in consecutive memory cells in BIG-endian architecture represents  === 0xA0 8C 8C 6B
:biggrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'


tntsgoboom

Quote from: K_F on February 12, 2016, 01:57:45 AM
The following data segment starts at memory address 0x2300 (hexadecimal)
.data
printString BYTE "Assembly is fun",0      === (0x10) 16 bytes (including the end zero)
moreBytes BYTE 48 DUP(0)                    === (0x30) 48 bytes
dateIssued DWORD ?                            === (0x04) 4 bytes
dueDate DWORD ?                                === (0x04) 4 bytes
elapsedTime WORD ?                            === (0x02) 2 bytes

What is the hexadecimal address of dueDate?   === 0x2300 + 0x10 + 0x30 + 0x04  = 0x2344 (you don't include the dueDate size)

The other question I have:
The four-byte sequence 0xA0 0x8C 0x8C 0x6B stored in consecutive memory cells in a little-endian architecture represents  === 0x6B 8C 8C A0 ( just convert this to decimal with the normal methods)
The four-byte sequence 0xA0 0x8C 0x8C 0x6B stored in consecutive memory cells in BIG-endian architecture represents  === 0xA0 8C 8C 6B
:biggrin:

Thank you very much for the thorough explanation. Why is it that You don't have to include dueDate size or elapsedTime ?

Not to worry JJ this isn't homework. I am seeking extra help because an exam is coming up and I want to make sure I understand the concepts. Without a thorough explanation I don't see how that goal would be met. Thank you for taking the time to answer as well. I appreciate it. 

K_F

tntsgoboom had already made many attempts to understand the concept, so a thorough explanation was necessary.

QuoteWhy is it that You don't have to include dueDate size or elapsedTime
When you load a variable the address pointer must point to the beginning of the desired variable (ie: byte 0 in the 4 byte DWORD sequence)

Think of a conveyor belt of green apples going down the line.. and you want to pick out the red apple further up.
You stick your hand out only after green apple, prior the red one has passed, and grab the red apple.
;)

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

tntsgoboom

I was able to understand the two problems above with the help, Thanks. I have two more questions. I will provide the answers. I am curious what the thought process is behind them and how to get to the answer.

Suppose that you are given the following program. What decimal value does the AX register hold when someProcedure is called??  The answer is 9562.

.data
x DWORD 153461
y BYTE 37
z BYTE 90


.code
main PROC
mov AH, y
mov AL, z
call someProcedure
inc EAX
mov EBX, z
xor EAX, EBX
exit
main ENDP
END MAIN

The other question (answer is 2004h):

In the following data definition, assume that List2 begins at offset 2000h. What is the offset of the third value (5)?

List2 WORD 3,4,5,6,7
1. 2002h
2. 2008h
3. 2006h
4. 2004h
5. 2008h
6. 2000h

dedndave

technically, you should probably clear the high word of EAX   :biggrin:

37 decimal is 25h
90 decimal is 5Ah

AX = 255Ah = 9562 decimal

the address problem - you should be able to solve that one
i know the answer, though   :lol:

tntsgoboom

oh is that all you had to do to solve the first one. Just convert the two decimal values to hex then add them.

K_F

Quote from: dedndave on February 12, 2016, 08:00:18 PM
technically, you should probably clear the high word of EAX   :biggrin:
Dave's right here as many 'newbies' get caught out with this when mixing different variable sizes in register ( Byte=8bits, Word=16bits, Dword=32bits)

If you're moving values that are of smaller size to a larger register, it's best to zero the register before the move.
xor eax, eax      ;EAX = 0x00000000
mov ah, 8          ;EAX = 0x00000800
mov al, 3           ;EAX = 0x00000803
mov ax, 0x300  ;EAX = 0x00000300

Here you see the top 16 bits (high word) are zero, and you wont get any surprises.
The Low Word is the AX or AH + AL registers. (AH and AL being 8 bits each)

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'


dedndave

my answer in reply #8 was designed to make you think
it is not the answer you really wanted

think about what you are doing when you place a value in AH and in AL, then use AX as a single value

AX = 256*AH+AL

you can solve directly (in decimal) using that equation

a similar case holds true for EAX being split into words
however, there are no instructions to directly access the high word of EAX without also accessing AX
well - there are a few for you to think about...

    and     eax,0FFFFh
    and     eax,0FFFF0000h
    or      eax,0FFFF0000h