Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the subject is : computer organization and assembly language strictly follow the instructions given below important instructions only answer if you know the correct answer

the subject is : computer organization and assembly language

strictly follow the instructions given below

important instructions

only answer if you know the correct answer

do not just put the answer explain in step by step of the answer

do step by step explanation in detail of the problem

Attention:

explain the problem in each question and then write its solution with proper explanation.

If you just write down the solution without any explanation it will be considered copied and you will lose marks

------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------

questions these given blew 4-question are to be answered

image text in transcribed

------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------

Chapter 4 Section 4.4 - Book (By Bilal Hashmi) for refrence if you don't need it you can skip this but it can help you in your answer

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Extended Operations (Chapter 4 - Section 4.4 - Book (By Bilal Hashmi)] 1. What are extended operations? 2. Explain extended Shifting? 3. Extended Addition and subtraction. 4. Extended Multiplication 4.4. EXTENDED OPERATIONS We performed a 4bit multiplication to explain the algorithm however the real advantage of the computer is when we ask it to multiply large numbers, Numbers whose multiplication takes real time. If we have an 8bit number we can do the multiplication in word registers, but are we limited to word operations? What if we want to multiply 32bit or even larger numbers? We are certainly not limited. Assembly language only provides us the basic building blocks. We build a plaza out of these blocks, or a building, or a classic piece of architecture is only dependant upon our imagination. With our logic we can extend these algorithms as much as we want. Our next example will be multiplication of 16bit numbers to produce a 32bit answer. However for a 32bit answer we need a way to shift a 32bit number and a way to add 32bit numbers. We cannot depend on 16bit shifting as we have 16 significant bits in our multiplicand and shifting any bit towards the left may drop a valuable bit causing a totally wrong result. A valuable bit means any bit that is one. Dropping a zero bit doesn't cause any difference. So we place the 16it number in 32bit space with the upper 16 bits zeroed so that the sixteen shift operations don't cause any valuable bit to drop. Even though the numbers were 16bit we need 32bit operations to multiply correctly. To clarify this necessity, we take example of a number 40000 or 9C40 in hexadecimal. In binary it is represented as 1001110001000000. To multiply dd 40000 rel by two we shift it one place to the left. The answer we get is 0011100010000000 and the left most one is dropped in the carry flag. The answer should be the 17bit number 0x13880 but it is 0x3880, which are 14464 in decimal instead of the expected 80000. We should be careful of this situation whenever shifting is used. Extended Shifting Using our basic shifting and rotation instructions we can effectively shift a 32bit number in memory word by word. We cannot shift the whole number at once since our architecture is limited to word operations. The algorithm we use consists of just two instructions and we name it extended shifting. numi: shl word [numl], 1 word (numl+2), 1 The DD directive reserves a 32bit space in memory, however the value we placed there will fit in 16bits. So we can safely shift the number left 16 times. The least significant word is accessible at numl and the most significant word is accessible at numl+2. The two instructions are carefully crafted such that the first one shifts the lower word towards the left and the most significant bit of that word is dropped in carry. With the next instruction we push that dropped bit into the least significant bit of the next word effectively joining the two 16bit words. The final carry after the second instruction will be the most significant bit of the higher word, which for this number will always be zero. The following illustration will clarify the concept. The pipe on the right contains the lower half and the pipe on the left contains the upper half. The first instruction forced a zero from the right into the lower half and the left most bit is saved in carry, and from there it is pushed into the upper half and the upper half is shifted as well. Step 1 C alolalalolatolore lo ch 110l1111olilolo Step 2 dd rcr For shifting right the exact opposite is done however care must be taken to shift right the upper half first and then rotate through carry right the lower half for obvious reasons. The instructions to do this are. numi: 40000 shr word [numl+2), 1 word (numi), 1 The same logic has worked. The shift placed the least significant bit of the upper half in the carry flag and it was pushed from right into the lower half. For a singed shift we would have used the shift arithmetic right instruction instead of the shift logical right instruction. The extension we have done is not limited to 32bits. We can shift a number of any size say 1024 bits. The second instruction will be repeated a number of times and we can achieve the desired effect. Using two simple instructions we have increased the capability of the operation to effectively an unlimited number of bits. The actual limit is the available memory as even the segment limit can be catered with a little thought. Extended Addition and Subtraction We also needed 32bit addition for multiplication of 16bit numbers. The idea of extension is same here. However we need to introduce a new instruction at this place. The instruction is ADC or "add with carry." Normal addition has two operands and the second operand is added to the first Virtual University of Pakistan 48 Computer Architecture & Assembly Language Programming CS401@vu.edu.pk Course Code: CS401 10 operand. However ADC has three operands. The third implied operand is the carry flag. The ADC instruction is specifically placed for extending the capability of ADD. Numbers of any size can be added using a proper combination of ADD and ADC. All basic building blocks are provided for the assembly language programmer, and the programmer can extend its capabilities as much as needed by using these fine instructions in appropriate combinations, Further clarifying the operation of ADC, consider an instruction "ADC AX, BX." Normal addition would have just added BX to AX, however ADC first adds the carry flag to AX and then adds EX to AX. Therefore the last carry is also included in the result. The algorithm should be apparent by now. The lower halves of the two numbers to be added are first added with a normal addition. For the upper halves a normal addition would lose track of a possible carry from the lower halves and the answer would be wrong. If a carry was generated it should go to the upper half. Therefore the upper halves are added with an addition with carry instruction. Since one operand must be in register, ax is used to read the lower and upper halves of the source one by one. The destination is directly updated. The set of instructions goes here. dest: dd 40000 3000 mOvex, (sel add word deal. 3x MOV, 21 de word dat 21. To further extend it more addition with carries will be used. However the carry from last addition will be wasted as there will always be a size limit where the results and the numbers are stored. This carry will remain in the carry flag to be tested for a possible overflow For subtraction the same logic will be used and just like addition with carry there is an instruction to subtract with borrows called SBB. Borrow in the name means the carry flag and is used just for clarity. Or we can say that the carry flag holds the carry for addition instructions and the borrow for subtraction instructions. Also the carry is generated at the 17th bit and the borrow is also taken from the 17th bit. Also there is no single instruction that needs borrow and carry in their independent meanings at the same time. Therefore it is logical to use the same flag for both tasks. We extend subtraction with a very similar algorithm. The lower halves must be subtracted normally while the upper halves must be subtracted with BC: dd time. Therefore it is logical to use the same flag for both tasks. We extend subtraction with a very similar algorithm. The lower halves must be subtracted normally while the upper halves must be subtracted with a subtract with borrow instruction so that if the lower halves needed a borrow, a one is subtracted from the upper halves. The algorithm is as under. dd 40000 dd 80000 movax, (sre) sub word (dest), ax movax, (src+2) sbb word (dest+2), ax dest: src: Extended Multiplication We use extended shifting and extended addition to formulate our algorithm to do extended multiplication. The multiplier is still stored in 16bits since we only need to check its bits one by one. The multiplicand however cannot be stored in 16bits otherwise on left shifting its significant bits might get lost. Therefore it has to be stored in 32bits and the shifting and addition used to accumulate the result must be 32bits as well. Extended Multiplication We use extended shifting and extended addition to formulate our algorithm to do extended multiplication. The multiplier is still stored in 16bits since we only need to check its bits one by one. The multiplicand however cannot be stored in 16bits otherwise on left shifting its significant bits might get lost. Therefore it has to be stored in 32bits and the shifting and addition used to accumulate the result must be 32bits as well. Example 4.2 Virtual University of Pakistan 49 Computer Architecture & Assembly Language Programming CS401avu.edu.pk Course Code: CS401 VU 20 skip 01 ; 16bit multiplication 02 [or 0x01001 03 japstart os multiplicand: dd 1300 ; 16bit multiplicand 32bit space 06 multiplier: dw 500 ; 16bit multiplier 07 results 0 ; 32bit result OB 09 start: movel, 16 ; initialize bit count to 16 10 mov dx [multiplier] ; load multiplier in dx checkbit: she dx, 1 ; move right most bit in carry jne akip ; skip addition if it is RED 14 15 ax, [multiplicand] add [result), a add less significant word ax, (multiplicand+21 ade result+2), ax ; add more significant word sh) word (multiplicand], 1 rel word [multiplicand+2], 1; shift multiplicand left dee el decremant hit count jna cheekhit ; repeat if bits left mov, 0x400 : terminate program 26 int 021 05-07 The multiplicand and the multiplier are stored in 32bit space while the multiplier is stored as a word. 10 The multiplier is loaded in DX where it will be shifted bit by bit. It can be directly shifted in memory as well. 15-18 The multiplicand is added to the result using extended 32bit addition. 20-21 The multiplicand is shifted left as a 32bit number using extended shifting operation. The multiplicand will occupy the space from 0103-0106, the multiplier will occupy space from 0107-0108 and the result will occupy the space from 0109-010C. Inside the debugger observe the changes in these memory locations during the course of the algorithm. The extended shifting and addition operations provide the same effect as would be provided if there were 32bit addition and shifting operations available in the instruction set. At the end of the algorithm the result memory locations contain the value 0009EB10 which is 65000 in decimal; the desired answer. Also observe that the number 00000514 which is 1300 in decimal, our multiplicand, has become 05140000 after being left shifted 16 times. Our extended shifting has given the same result as if a 32bit number is left shifted 16 times as a unit. There are many other important applications of the shifting and rotation operations in addition to this example of the multiplication algorithm. More examples will come in coming chapters

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions

Question

What are the social tasks and challenges of adolescence?

Answered: 1 week ago