Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

I though of posting this so that people can easily find matching solution if any questions repeat.

These are the VU solutions of VU teachers from VULMS.

 

Assignment No. 01
Semester: Fall 2012

CS401: Computer Architecture and Assembly Language Programming

Assignment Solution

 

 

Question No. 1:

 

Part (A):                          (5 marks)

 

Calculate physical address of the following segment offset pairs. Explain each and every step for calculating the physical address.

  1. 2C3E:0199
  2. 8000:0250

Solution:

Segment Address = Segment Register x 10.

Offset Address = Logical Address.

Physical Address = Segment address + Offset Address

 

  1. 1.     2C3E:0199

Segment Address = 2C3E x 10 = 2C3E0.

Offset Address = 00199.

 

Physical Address = 2C3E0 + 00199 = 2C579.

 

  1. 2.     8000:0250

Segment Address = 8000 x 10 = 80000.

Offset Address = 0250.

 

Physical Address = 80000 + 00250 = 80250.

 

 (Calculation:3 marks & Explanation:2 marks)    

Part (B):

Assemble the given program using NASM.  

(5 marks)

ORG 0100H

MOV AX,5H

ADD AX,44ABH

MOV BX,10

ADD AX,BX

SUB AX,0F12H

MOV BX,15

ADD AX,BX

MOV AX,0X4C00

INT 0X21

 

 

 

 

 

 

Instruction

Register current value after the instruction execution

IP

(Instruction Pointer)

Flags

CF

ZF

PF

SF

AF

1

ORG 0100H

AX

0000

0100

0

0

0

0

0

BX

0000

2

MOV AX,5H

AX

0005

0103

0

0

0

0

0

BX

0000

3

ADD AX,44ABH

AX

44B0

0106

0

0

0

0

1

BX

0000

4

MOV BX,10

AX

44B0

0109

0

0

0

0

1

BX

000A

6

ADD AX,BX

AX

44BA

010B

0

0

0

0

0

BX

000A

7

SUB AX,0F12H

AX

35A8

010E

0

0

0

0

0

BX

000A

8

MOV BX,15

AX

35A8

0111

0

0

0

0

0

BX

000F

9

ADD AX,BX

AX

35B7

0113

0

0

1

0

1

BX

000F

Table: Register contents after the execution of each instruction.

 

Question No. 2:                                    (10 marks)

    

 

Now after attempting previous question, You are able to write, assemble and debug a program. So write a program using Conditional Jump instructions that will add all odd numbers between 1 to 20 (not including 1 & 20). Explain each instruction of program in your own words and also attach the snapshot of your AFD showing the executed code results.

Solution:

 

[ORG 0X100]

MOV AX,3                 ; Initializing AX by 3

MOV CX,3                 ; Initializing CX by 3

 

LOOP_ADD:              ADD CX,2                  ; Incrementing CX by 2 for ODD numbers

ADD AX,CX               ; Adding CX in AX

CMP CX,19                ; checking whether the final ODD number reached

JNE LOOP_ADD        ; if not, jump to add next ODD number

 

MOV AX,0X4C00

INT  0X21

 

(Program:5 marks, Explanation: 3 marks & Snapshot: 2 marks)

Note: Provide snapshot of your program which will be run in AFD window. It is strictly prohibited the copied assignment.

 

 

Views: 694

Attachments:

Replies to This Discussion

Assignment No. 02
Semester: Fall 2012

CS401: Computer Architecture and Assembly Language Programming

Assignment2 solution

 

 

Question No. 1:

 

Assemble the given Subroutine program using NASM to add three numbers array using a subroutine named as “sumofarray” and show the changes occurs in AX, BX & CX on each step.

 

(10 marks)

[ORG 0x0100]

 

MOV BX, VAL           

MOV CX, 3     

MOV AX, 0

                       

CALL SUMOFARRAY

 

MOV AX, 0X4C00      

INT 0X21

 

SUMOFARRAY:          ADD AX, [BX]            

ADD BX, 2     

SUB CX, 1                  

JNZ SUMOFARRAY                           

MOV [SUM], AX        

RET

 

VAL: DW 30,40,50

SUM: DW 0

 

 

  1. When the program is loaded in the debugger, it is loaded at offset 0100, which displaces all memory accesses in our program. Execute the program step by step and examine how the memory is read and the registers are updated, how the instruction pointer moves forward.

 

  1. Now we execute the program with F2 key (instruction will move one by one) and using F1 key is used to trace the call subroutine. Write down the contents of the specified registers in the given table.

 

 

 

 

 

 

 

 

 

 

 

 

Instruction

Register current value after the instruction execution

IP

(Instruction Pointer)

Flags

CF

ZF

PF

SF

AF

1

[ORG 0x0100]

AX 0000

0100

0

0

0

0

0

BX 0000

CX  0029

2

MOV BX, VAL

AX  0000

0103

0

0

0

0

0

BX  0121

CX  0029

3

MOV CX, 3

AX0000

0106

0

0

0

0

0

BX   0121

CX  0003

4

MOV AX, 0

AX 0000

0109

0

0

0

0

0

BX    0121

CX   0003

5

CALL SUMOFARRAY

 

0111

6

MOV AX, 0X4C00

 

7

INT 0X21

 

8

 

SUMOFARRAY:

 

 

ADD AX, [BX]

AX  001E

0113

0

0

1

0

0

BX  0121

CX  0003

 

ADD BX, 2

AX  001E

0117

0

0

0

0

0

BX   0123

CX   0003

 

SUB CX, 1

AX  001E

011b

0

0

0

0

0

BX   0123

CX   0002

9

 

SUMOFARRAY:

 

 

ADD AX, [BX]

 

AX  0046

 

 

0113

 

0

0

0

0

1

 

 

BX  0123

CX 0002

 

ADD BX,2

AX 0046

0117

0

0

0

0

0

 

 

 

 

 

 

 

BX 0125

CX 0002

 

 

SUB CX,1

AX 0046

011b

0

0

0

0

0

BX 0125

CX 0001

 

10

 

SUMOFARRAY:

 

 

ADD AX, [BX]

 

AX 0078

0113

0

0

1

0

0

BX 0125

CX 0001

 

ADD BX,2

AX  0078

0117

0

0

1

0

0

BX  0127

CX  0001

 

 

SUB CX,1

AX  0078

011B

0

0

1

0

0

BX  0127

CX  0000

11

MOV [SUM], AX

AX  0078

011D

0

1

1

0

0

BX  0127

CX  0000

 

 

Q2.Now after attempting previous question, you are able to write, assemble and debug a Subroutine program. So write an assembly language code to find the minimum number from an array of ten numbers using a subroutine. Explain each instruction of program in your own words and also attach the snapshot of your AFD showing the executed code final results.

 

(Program using subroutine:5 marks,

Explanation: 3 marks,

Snapshot: 2 marks)

Note: Provide snapshot of your program which will be run in AFD window. It is strictly prohibited the copied assignment.

 

[ORG 0X0100]

JMP START

 

ARRAY10: DW   20, 7, 30, 14, 19, 3, 5, 6, 40, 8

MIN: DW   0

 

MINVALUE: CMP  AX, [ARRAY10 +BX]              ; ARE WE FIND THE MINIMUM NUMBER

JLE MINLOOP                                                           ; IF LESS OR EQUAL NUMBER

MOV AX,[ ARRAY10 +BX]            ;AX CONTAINS THE MINIMUM NUMBER

 

MINLOOP:     ADD  BX, 2                ; ADVANCE BX TO NEXT INDEX

                        LOOP MINVALUE

                        MOV  [MIN], AX                   ; WRITE BACK MINIMUM IN MEMORY

                        RET

 

 

 

START:          MOV BX, 0                            ; INITIALIZE ARRAY INDEX TO ZERO

MOV  AX, 0                           ; INITIALIZE MIN TO ZERO

                        MOV  AX, [ARRAY10 +BX]            ; MINIMUM NUMBER TO AX

MOV CX,10

CALL MINVALUE                                        ; CALL OUR SUBROUTINE

 

MOV AX, 0X4C00                             ; TERMINATE PROGRAM

INT 0X21

 

 

FINAL SNAPSHOT:

 

Attachments:

Assignment No. 03
Semester: Fall 2012

CS401: Computer Architecture and Assembly Language Programming

Objective

 

The objective of this assignment is to enhance your knowledge about;

 

  • Software Interrupts
  • Real Time Interrupts and Hardware Interfacing

 

 

Assignment No. 3

 

 

Question: 1

In this assignment, you have to deal with parallel ports as shown in Fig: 1.You have to read and write the parallel port’s data block using IN and OUT instructions.

We can control AC devices (switching them ON/OFF) by interfacing them with system’s Parallel Port as shown in Fig: 2.We have to use some external Electrical switching circuitry which needs some expertise to design it that will switch those devices ON or OFF depending upon the Parallel Port’s PIN status either Set (1) or Cleared (0).

 

                                                                Fig: 2

 Suppose we have interfaced 5 different AC devices with our system’s parallel port and want those to be controlled using five different keyboard keys.

You have to write an assembly code that will read the device status (read the parallel port) and on the basis of that status, it will turn the specific device ON or OFF depending upon your input provided through keyboard as shown in Table: 1.

Keyboard Key

Data pin linked

Device Controlled or Action Performed

F

Data Pin 0

FAN Controlled

L

Data Pin 1

Light Controlled

T

Data Pin 2

Television Controlled

D

Data Pin 3

DVD player Controlled

S

Data Pin 4

Sound System Controlled

Q

NIL

Program Exit/Quit/Terminate

Table: 1

In your code, you have to read an input character (ASCII code only) from keyboard and then have to send a specific HEX value to parallel port to turn ON or OFF the specific device (depends upon the current state).

Note: If a device is ON, by pressing the assigned key the device should be set to OFF or vice versa. For example, if you have pressed “F” to switch ON the FAN then by pressing the key “F” again will switch OFF the FAN as shown in Table: 2.

You have to write a code in assembly language using ASCII standard that take an input character from keyboard (Capital letters:F, L, T, D, S and Q) and on the basis of these characters, you have to control attached AC devices via the parallel port.

 

Key Pressed

D0

D1

D2

D3

D4

F

1

0

0

0

0

L

0

1

0

0

0

T

0

0

1

0

0

D

0

0

0

1

0

S

0

0

0

0

1

Q

0

0

0

0

0

 

Table: 2

SOLUTION:

 

ORG 0100H

 

                        XOR AX, AX                           ; clearing AX

                        XOR DX, DX                           ; clearing DX

 

MAIN:            

                        MOV AH, 1H                           ; keyboard input

INT 21H                                   ; read character into AL

 

CMP AL, 46H                          ; compare AL with “F”

JE FAN                                                ; jump to “FAN control”

 

CMP AL, 4CH                          ; compare AL with “L”

                        JE LIGHT                                 ; jump to “Light Control”

 

CMP AL, 54H                          ; compare AL with “T”

JE TELEVISION                      ; jump to “Television Control”

 

CMP AL, 44H                          ; compare AL with “D”

JE DVD                                    ; jump to “DVD Control”

 

CMP AL, 53H                          ; compare AL with “S”

JE SOUND                               ; jump to “Sound System Control”

 

CMP AL, 51H                          ; compare AL with “Q”

JE QUIT                                   ; jump to “Quit and reset Control”

 

JMP MAIN                               ; jump to main program

 

FAN:                MOV DX, 0x378

                        IN AL, DX                               ; reading parallel port’s current state

                        XOR AL, 01H                          ; setting FAN state to ON or OFF                                 

OUT DX, AL                            ; writing data to Parallel port

JMP MAIN

 

LIGHT:            MOV DX, 0x378

                        IN AL, DX                               ; reading parallel port’s current state

                        XOR AL, 02H                          ; setting LIGHT state to ON or OFF                             

OUT DX, AL                            ; writing data to Parallel port

JMP MAIN

 

 

TELEVISION:  MOV DX, 0x378

                        IN AL, DX                               ; reading parallel port’s current state

                        XOR AL, 04H                          ; setting TELEVISION state to ON or OFF                                             OUT DX, AL                           ; writing data to Parallel port

JMP MAIN

 

DVD:               MOV DX, 0x378

                        IN AL, DX                               ; reading parallel port’s current state

                        XOR AL, 08H                          ; setting DVD state to ON or OFF                                

OUT DX, AL                            ; writing data to Parallel port

JMP MAIN

 

SOUND:           MOV DX, 0x378

                        IN AL, DX                               ; reading parallel port’s current state

                        XOR AL, 10H                          ; setting SOUND SYSTEM state to ON or OFF                                     OUT DX, AL                            ; writing data to Parallel port

JMP MAIN

 

QUIT:              MOV DX, 0x378

                        MOV AL, 00H                          ; setting all devices to OFF state

                        OUT DX, AL                            ; write data to parallel port       

                        MOV AX, 4C00H

INT 21H

 

 

 

Files for Assignment 3

Attachments:

Assignment No. 04
Semester: Fall 2012

CS401: Computer Architecture and Assembly Language Programming

Objective

 

The objective of this assignment is to enhance your knowledge about;

 

  • Debugging interrupts

 

Assignment No. 4

 

 

Question: 1

A debugger or debugging tool is basically software that is used to test/debug programs. It has the ability to fetch an instruction, decode and execute that instruction. After each and every instruction a debugger can give control back to the user through its user interface or it can have ability to have a breakeven point.

 

Suppose you are assigned to write a code that will debug an interrupts using internal support provided through assembly language. So you have to answer the following question that your code/program is justifying the basic objectives that a debugger should have.

 

  1. 1.     Which interrupts in assembly language programming can be used in debugging an interrupt and how their functionality matches the debugging process?        

                                                                                                                      (Marks: 10)

 

  1. How your code will counter fault and trap exception?                                  

                                                                                                                      (Marks: 5)

 

 

  1. Which flag will be used in debugging an interrupt and how?                        

                                                                                                                      (Marks: 5)

 

Solution:

  1. INT 1 and INT3 are using in “debugging” process.

 

a)     Functionality:

 

1. INT1 is single step interrupt that wait for a key hit after every instruction’s execution. It is similar to debugger behavior which displays all its register contents after each instruction’s execution and wait for a key hit from a user.

Debugger has a break point characteristic. INT3 is used for this feature. To put a break point the instruction is replaced with INT3 op-code and restored in interrupt 3 handler.

 

2. In case of fault exception, the address of that instruction on which the fault has been occurred, it is push on the stack While in trap exception, the address of the next instruction is push on the stack.

3. Trap flag plays an important role in debugging. There is no instruction through which we can set or clear the trap flag like in case of other flags. We have two instructions PUSHF and POPF that used to push and pop the flag from the stack. We use PUSHF to place flags on the stack, then change trap flag in stack and then reload them back to the flags register with POPF. After the flag register is reloaded from stack, the single step interrupt will occur after the execution of first instruction. The single step interrupt will automatically clears interrupt flag and trap flag otherwise there would an infinite recursion of the single step interrupt.

Files for assignment 4

Attachments:

Note: (This is Featured Discussion)

For Important Helping Material related to this subject (Solved MCQs, Short Notes, Solved past Papers, E-Books, FAQ,Short Questions Answers & more). You must view all the featured Discussion in this subject group.

For how you can view all the Featured discussions click on the Back to Subject Name Discussions link below the title of this Discussion & then under featured Discussion corner click on the view all link.

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service