CS401 Midterm Short Notes by Study with BRD
- Type
- Midterm past paper
- Course
- CS401 Computer Architecture and Assembly Language Programming
- Size
- PDF 571 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 14. Download the file for all 14 pages.
Normal addition has two operands and the second operand is added to the first 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. Further more 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 BX to AX. Therefore the last carry is also included in the result. 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.
What is the difference between LES and LDS instructions ?
Describe local variables.
Another important role of the stack is in the creation of local variables that are only needed while the subroutine is in execution and not afterwards. They should not take permanent space like global variables. Local variables should be created when the subroutine is called and discarded afterwards. So that the spaced used by them can be reused for the local variables of another subroutine. They only have meaning inside the subroutine and no meaning outside it. The swapflag we have declared as a word occupying space permanently is only needed by the bubble sort subroutine and should be a local variable. Actually the variable was introduced with the intent of making it a local variable at this time. The stack pointer will be decremented by an extra two bytes thereby producing a gap in which a word can reside. This gap will be used for our temporary, local, or automatic variable; however we name it. We can decrement it as much as we want producing the desired space, however the decrement must be by an even number, as the unit of stack operation is a word. In our case we needed just one word. Also the most convenient position for this gap is immediately after saving the value of SP in BP. So that the same base pointer can be used to access the local variables as well; this time using negative offsets. The standard way to start a subroutine which needs to access parameters and has local variables is as under. push bp mov bp, sp sub sp, 2 The gap could have been created with a dummy push, but the subtraction makes it clear that the value pushed is not important and the gap will be used for our local variable. Also gap of any size can be created in a single instruction with subtraction. The parameters can still be accessed at bp+4 and bp+6 and the swapflag can be accessed at bp-2. The subtraction in SP was after taking the snapshot; therefore BP is above the parameters but below the local variables. The parameters are therefore accessed using positive offsets from BP and the local variables are accessed using negative offsets.
mov bp,sp push ax push cx push si push di push es push ds
mov si, ax push si shl si, 1 mov cx, 2000 sub cx, ax mov ax, 0xb800 mov es, ax mov ds, ax xor di, di cld rep movsw ; scroll up mov ax, 0x0720 pop cx rep stosw pop ds pop es pop di pop si pop cx pop ax pop bp ret 2
What is difference between SHR and SAR instructions?
SHR The SHR inserts a zero from the left and moves every bit one position to the right and copy the rightmost bit in the carry flag.
SAR
The SAR shift every bit one place to the right with a copy of the most significant bit left at the most significant place. The bit dropped from the right is caught in the carry basket. The sign bit is retained in this operation.
mov bp,sp push es push cx push di les di, [bp+4]
xor al, al
sub ax, cx dec ax ; exclude null from length pop di pop cx pop es pop bp ret 4
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.
num1: dd 40000
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 num1 and the most significant word is accessible at num1+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 CALL instruction allows temporary diversion and therefore reusability of code. The word return holds in its meaning that we are to return from where we came and need no explicit destination. Therefore RET takes no arguments and transfers control back to the instruction following the CALL that took us in this subroutine.
Related CS401 files
All CS401 files →- CS401 Midterm MCQs by Talha Sajid Midterm PDF 1 MB
- CS401 Midterm Past Papers by Waqar Siddhu Midterm PDF 7.5 MB
- CS401 Midterm MCQs by Danish Hanif Midterm PDF 2.1 MB
- CS401 Midterm Subjective Set 2 by Waqar Siddhu Midterm PDF 1.9 MB
- CS401 Highlighted Handouts by Mickey Ch Highlighted PDF 7.2 MB
- CS401 Solved Quiz 2 by Waqar Siddhu Quiz RAR 820 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.