Discussion: HW-M5

Post questions about Section 4.9.2 of textbook Assembly Programming: prob 13- Section 4.10 probs 1,2,3,4, 5. Use the first line of your post as the subject of the post.

 

loose llama posted at 2021-07-09T18:17:36.000Z

32-bit mode or 64-bit mode?

 

The homework says that the programming exercises can be completed in 32 or 64 bit mode.  I know we are focused on 32 bit only but is it acceptable to submit 64 bit mode for these programming exercises?

 

"4.10 Programming Exercises

The following exercises may be completed in either 32-bit mode or 64-bit mode."

financial fowl posted at 2021-07-13T07:51:22.000Z

The professor said a while ago that no matter what the homework said, you should only focus on writing your code on 32 bit. 

insufficient junglefowl posted at 2021-07-14T03:28:48.000Z

This entire class is in 32-bit mode.

electoral dragon posted at 2021-07-18T19:19:49.000Z

I agree that the hw should be done in 32 bit mode. But also wanted to ask if this means that it is ok to skip the sections in the book that specifically talk about 64 bit mode?

occasional muskox posted at 2021-07-18T22:10:24.000Z

I don't believe we need to worry about the 64-bit content.

 

skilled silkworm posted at 2021-07-19T01:03:10.000Z

32 bit mode is what we are learning so far. We might have some opportunity to learn 64 bit mode at the end.

breezy bird posted at 2021-07-19T06:02:51.000Z

Yep, 32 bit is what we have been learning and is going to be in 32 - bit mode for the entire class.

thin tick posted at 2021-07-19T06:18:00.000Z

I was wondering this as well because of the professor's emphasis on only using 32-bit.

hilarious harrier posted at 2021-07-19T10:27:07.000Z

Should be 32 bit mode

 

dizzy cuckoo posted at 2021-07-13T02:55:17.000Z

Just a note from the class tonight on programming homework submission for:

Only submit .code section in a text file, plus .data section if you have declared any data. The purpose is that the professor can then copy your code and execute it in a non-Microsoft assembler.  Thanks!

secure salamander posted at 2021-07-14T02:55:27.000Z

I submitted way more than this, but I'll keep it in mind from now on.

consistent centipede posted at 2021-07-16T21:50:02.000Z

Thanks for making note of this, I also have been submitting the entire .asm file, so knowing that we only need to include the .data & .code is better.

statutory squirrel posted at 2021-07-16T22:12:39.000Z

Thanks a bunch! Great to know this,

ugliest trout posted at 2021-07-19T03:56:21.000Z

Thank you so much!

faithful firefly posted at 2021-07-19T04:18:26.000Z

Also, and this has been said a million times, you can leave out the main proc, exitprocess, and dumpregs/other irvine stuff.

abstract aardwolf posted at 2021-07-19T05:03:11.000Z

Thanks for the reminder! Good to know this.

conscious cattle posted at 2021-07-19T05:48:33.000Z

Thank you Amy. Glad to know about this.

close buzzard posted at 2021-07-19T05:59:41.000Z

It just makes it easier for the professor, as the other parts are not implemented by us and is just part of the template to make sure it compiles.

breezy bird posted at 2021-07-19T06:03:23.000Z

Thank you, would have totally missed this!

surviving takin posted at 2021-07-19T06:05:30.000Z

Will we be marked off if we submitted the whole thing already? (for former homeworks)

overseas orca posted at 2021-07-19T06:15:36.000Z

Thanks, appreciate it! Totally would've missed this.

professional pigeon posted at 2021-07-14T04:32:20.000Z

Fibonacci numbers in Assembly?

how do we implement it?

insufficient junglefowl posted at 2021-07-16T06:55:01.000Z

Here are some examples from stack overflow:

https://stackoverflow.com/questions/32659715/assembly-language-x86-how-to-create-a-loop-to-calculate-fibonacci-sequence

statutory squirrel posted at 2021-07-16T22:14:29.000Z

Hi there! Summer gave a nice resource. Here is another useful one: https://chevythunder82.tripod.com/coursework/COMP235/fibonacci.html

envious earwig posted at 2021-07-18T05:49:47.000Z

Hi! Here is a good resource that also provides other helpful links:https://www.programmersought.com/article/20332992916/ (Links to an external site.)

tough toad posted at 2021-07-18T18:45:29.000Z

Hey!  I also found another link that might be helpful!

https://titanwolf.org/Network/Articles/Article?AID=fb26d35b-eba3-4dee-afcc-0e64ac5cad86#gsc.tab=0

implicit hoverfly posted at 2021-07-18T21:41:50.000Z

I had the same difficulty. So I found a good material while searching.

https://stackoverflow.com/questions/32659715/assembly-language-x86-how-to-create-a-loop-to-calculate-fibonacci-sequence

relieved quail posted at 2021-07-18T23:41:49.000Z

Thank you for the resources. They are helping me out!

agricultural ant posted at 2021-07-19T06:03:19.000Z

This is what I used:https://blog.seso.io/posts/creating-a-fibonacci-generator-in-assembly/ (Links to an external site.)

 

skilled silkworm posted at 2021-07-19T06:51:10.000Z

Hi Darren,

This is one of the tough questions in my opinion. This is where I went for further materials

https://assembly.happycodings.com/code1.html (Links to an external site.)

I hope this helps.

easy dolphin posted at 2021-07-16T07:23:04.000Z

Converting from Big Endian to Little Endian

In problem 1 of section 4.10, it is my understanding from the question that the order of the bytes in bigEndian should be reversed in littleEndian, i.e, it should be 78h, 56h, 34h, 12h. However, to me it looks like the chapter 4 solutions posted maintains the original order of bigEndian in littleEndian as well. Did I get this wrong? Please explain this to me. Thank you.

supposed swordtail posted at 2021-07-16T21:23:53.000Z

The chapter 4 solutions change it to little endian. It looks like it kept the byte ordering as big endian since DumpRegs prints out the bytes in big endian order. Try moving 1 to EAX and calling DumpRegs to see this.

grumpy haddock posted at 2021-07-16T22:57:25.000Z

In the book, section 4.5.3 shows how you can see the elements of an array while debugging, which could be helpful to see if the array becomes littleEndian.

easy dolphin posted at 2021-07-17T05:39:33.000Z

Thank you for your replies! This makes a bit more sense. 

dizzy cuckoo posted at 2021-07-18T04:11:11.000Z

Thanks this is very helpful while I am also struggling with HW. 

spatial snipe posted at 2021-07-19T01:23:00.000Z

https://stackoverflow.com/questions/35713272/big-endian-to-little-endian (Links to an external site.)has pretty good explanation of this problem. 

bigEndian BYTE 12h,34h,56h,78h

littleEndian will reverse the way it is stored. if i need to declare i will use

littleEndian BYTE 78h, 56h, 34h, 12h

To do it programmatically:  (using indirect addressing, reading from bigEndian array and then moving register values in opposite order - have to say little tricky to get it at first.  Another way implement is to use two pointers from start and end of array and keep swapping numbers at those pointers till it meets in the middle or low < high condition)

mov al,DWORD PTR bigEndian+0
mov ah,DWORD PTR bigEndian+1
mov bl,DWORD PTR bigEndian+2
mov bh,DWORD PTR bigEndian+3

mov littleEndian+0,bh
mov littleEndian+1,bl
mov littleEndian+2,ah
mov littleEndian+3,al
Cole Gannon posted at 2021-07-19T06:19:45.000Z

There is a x86 instruction to do it for you :)

relaxed python posted at 2021-07-18T20:16:26.000Z

Fibonacci Numbers question

I have some question with the problem 5 of section 4.10. I'm wondering how should I start this program with? Any other method than loop should I use?

puzzled pony posted at 2021-07-18T20:55:37.000Z

This might be a good resource to get started with pseudocode and diagram given.

dizzy cuckoo posted at 2021-07-18T21:08:20.000Z

Hello Yen-Jung!

Here is my approach:

The first and second Fibonacci numbers are given: both are 1. We need to find out the next 5 F numbers by summing the previous two Fibonacci numbers.

Declare data array of 7 elements, first two values known;

Declare count = 5, move to ECX. ECX is used the LOOP internally. 

Get the OFFSET of the data array

Move the pointer to the 3rd number (ADD ESI, TYPE array twice)

Inside the loop:

read the two numbers before the current location by using indexed addressing:

MOV eax, [ESI-4] -> move backwards 4 bytes to get the value immediately before current memory location;

MOV eax, [esi -8] - > move backwards 8 bytes,

Add above two values, assign to the memeory address of the current element memory. 

Move the pointer to next in the array. 

Hope this helps and good luck!

 

brief bird posted at 2021-07-19T03:05:29.000Z

These replies are really helpful as I was going to ask this same question. Thanks, everyone!

passive owl posted at 2021-07-18T21:46:31.000Z

PTR Using

I think I have to use PTR to get access to the array's item. Is my understanding correct?

For probs1, can I move the bigEndian array's item to bx(bh & bl) temporarily instead of ax(al & ah)?

enormous earthworm posted at 2021-07-19T01:49:50.000Z

According tohttps://stackoverflow.com/questions/2864011/accessing-arrays-element-in-assembly-language-windows (Links to an external site.)

I don't think you have to use a PTR 

genuine gopher posted at 2021-07-18T22:56:05.000Z

Problem 3 Summing the Gaps between Array Values

For question 3 what does it mean by the array {0, 2, 5, 9, 10} has gaps of 2, 3, 4, and 1 and whats the reason we need to know this?

entitled earwig posted at 2021-07-19T00:33:46.000Z

When it says gaps, it refers to the difference between consecutive array elements.

advanced anaconda posted at 2021-07-19T04:38:15.000Z

I think this question is a practice for us to loop through an array and do some calculations around it.

The gap means the difference between two consecutive array elements, which can be calculated by subtracting the left element by the right element. For example, 2-0=2, 5-2=3, 9-5=4, 10-9=1.

surviving takin posted at 2021-07-19T06:07:24.000Z

In addition to what Sarah stated, it's simply just an algebra problem that is solved using array functionalities so that's really all you need to know to figure it out.

geographical gopher posted at 2021-07-19T00:25:27.000Z

I'm confused on question 2:

If the input array is values 1,2,3,4,5,6 etc are they saying the output should be 2,1,4,3,6,5? This is also the midterm question so I need to make sure I don't get messed up by the wording lol. 

driving deer posted at 2021-07-19T05:23:26.000Z

Hi Aaron,

That is also how I interpreted the question. It says that item i needs to be swapped with item i+1, and then item i+2 with item i+3. So if i is 0, then item 0 is swapped with item 1, and item 2 is swapped with item 3. I believe that you must also assume that the array contains an even number of elements so you do not need to worry about the condition where there's an odd number.

conceptual catfish posted at 2021-07-19T01:34:28.000Z

Problem #2 - Exchanging Pairs of Array Values

Can someone further explain the instructions of this problem, I am not quite sure what I am suppose to be doing.

conceptual catfish posted at 2021-07-19T01:34:47.000Z

Problem #2 - Exchanging Pairs of Array Values

Can someone further explain the instructions of this problem, I am not quite sure what I am suppose to be doing.

entitled earwig posted at 2021-07-22T14:17:23.000Z

I think all you have to do is just use a loop and loop through moving and exchanging the register values.

moaning mastodon posted at 2021-07-19T05:02:56.000Z
I’m still very confused on question 5. Can someone give me a hint?
conscious cattle posted at 2021-07-19T06:09:24.000Z

Hey Aman, 

I found this on stackoverflow to initiate the question. Hope that helps.

assembly - X86 Fibonacci program - Stack Overflow (Links to an external site.)

civic bovid posted at 2021-07-19T08:28:20.000Z

Thank you Ajay. I'm stuck in this question too.