Showing posts with label CS401. Show all posts
Showing posts with label CS401. Show all posts

Monday, January 23, 2012

CS401 5 Computer Architecture and Assembly Language Programming assignment solution fall 2012

Assignment No. 05
Semester: Fall 2011
CS401: Computer Architecture and Assembly Language Programming

Question No. 1:                                         10 Marks

In Example 12.4 Line# 6, an instruction is given to define a greeting message as below:

6.  message: db 10, 13, 'hello $' ; greetings message

  • What is the purpose of including the values 10 and 13 as these values are not printed on output screen?

10 is used for new line. It is used to start a new line.    10 is the new line character in ASCII code.
   13 is the carriage return.
So they are not shown in output.

  • What is the purpose of writing $ at the end of the string message?

$ is a terminator character. We use the service no 09 of the DOS. This service takes the $ sign as the terminator of the string. 

Question No. 2:                                         10 Marks

This question is based upon Elementary multitasking of two threads Example 11.1 given in Lectures handouts. Given code in example 11.1 creates two simple threads each rotating bars by changing characters at the two corners of the screen and have infinite loops. Its output looks like as below:




Line #
Instruction to be added/modified
New/Modified Instruction
11
chars: db '\|/-'
chars: db '01234567'
17
and bx, 3
and bx, 7
24
and bx, 3
and bx, 7



Tuesday, January 10, 2012

cs401 Computer Architecture and Assembly Language Programming assignment solution fall 2012

this is incomplete solution

[org 0x0100]
jmp start

oldisr: dd 0
op: dw 0
swap: db 0
loc: dw 0
locc: dw 0

data: dw 2, 1, 4, 3, 6, 5, 8, 7, 10, 9

;========================number printing====================

 

printnum:
 push bp
 mov bp, sp
 push es
 push ax
 push bx
 push cx
 push dx
 push di
 mov ax, 0xb800
 mov es, ax
 mov ax, [bp+4]
 mov bx, 10
 mov cx, 0
nextdigit:
 mov dx, 0
 div bx ; divide by 10
 add dl, 0x30
 push dx
 inc cx
 cmp ax, 0
 jnz nextdigit
 mov di, 0

nextpos:
 pop dx
 mov dh, 0x07
;================================================
 mov ax,[loc]
 mov ah,0
 mov si,ax
 mov [es:si], dx
 add ax,2
 mov [loc],ax
;======================================
 add di, 2
 loop nextpos
 pop di
 pop dx
 pop cx
 pop bx
 pop ax
 pop es
 pop bp
 ret 2

;=========================================================
uuu:
 mov word[data],2
 mov word[data+2],1
 mov word[data+4],4
 mov word[data+6],3
 mov word[data+8],6
 mov word[data+10],5
 mov word[data+12],8
 mov word[data+14],7
 mov word[data+16],10
 mov word[data+18],9
 mov word[op],1

ret
;=====================================================

kbisr:
 push ax
 push es

 in al, 0x60
;=======================================================
 cmp al, 0x1f
 jne nomatch
call uuu
;=======================================================


mov bx, [locc]



 




 

;=============================================
 mov bp,0

 


ll:
 mov ax, [data+bp]
 push ax
 call printnum

 add bp,2
 cmp bp,20
  jne ll


 


;====================================================


jmp exit
;============================================================

nomatch:
 pop es
 pop ax
 jmp far [cs:oldisr]

;==================================================================
exit:
 mov al, 0x20
 out 0x20, al
 pop es
 pop ax
 iret
;=======================================================
start:


 xor ax, ax
 mov es, ax
 mov ax, [es:9*4]
 mov [oldisr], ax
 mov ax, [es:9*4+2]
 mov [oldisr+2], ax

 cli
 mov word [es:9*4], kbisr
 mov [es:9*4+2], cs
 sti


 mov dx, start
 add dx, 15
 mov cl, 4
 shr dx, cl
 mov ax, 0x3100
 int 0x21

Tuesday, December 27, 2011

CS401 3 Computer Architecture and Assembly assignment solution fall december 2011

Copy the following code in "NOTEPAD" and save as

filename.asm

submit the asm file in vulms.

Please makes changes before submitting.



 [org 0x0100]
jmp start
oldisr: dd 0
message1: db 'Hello'
message2: db 'World'
;===============================================
kbisr:
 push ax
 push es
 mov ax, 0xb800
 mov es, ax
 in al, 0x60
;=======================Hello===================
 cmp al, 0x23
 jne nextcmp


mov ah, 0x13
mov al, 0
mov bh, 0
mov bl, 7
mov dx, 0x0000
mov cx, 5
push cs
pop es
mov bp, message1
int 0x10
 
 jmp exit
;=======================World===================
nextcmp:
 cmp al, 0x11
 jne nextcmp1
mov ah, 0x13
mov al, 0
mov bh, 0
mov bl, 7
mov dx, 0x0000
mov cx, 5
push cs
pop es
mov bp, message2
int 0x10


 jmp exit


;====================clear screen===============
nextcmp1:
 cmp al, 0x2e
 jne nomatch


mov ax, 0xb800
mov es, ax
mov di, 0
nextchar:
mov word [es:di], 0x0720
add di, 2
cmp di, 4000
jne nextchar


 jmp exit


;===============================================


nomatch:
 pop es
 pop ax
 jmp far [cs:oldisr]
;===============================================
exit:
 mov al, 0x20
 out 0x20, al
 pop es
 pop ax
 iret
;===================main========================
start:
 xor ax, ax
 mov es, ax
 mov ax, [es:9*4]
 mov [oldisr], ax
 mov ax, [es:9*4+2]
 mov [oldisr+2], ax
 cli
 mov word [es:9*4], kbisr
 mov [es:9*4+2], cs
 sti


 mov dx, start
 add dx, 15
 mov cl, 4
 shr dx, cl
 mov ax, 0x3100
 int 0x21

Monday, November 14, 2011

CS401: Computer Architecture and Assembly Language Programming Assignment No. 02 Semester: Fall 2011

Suppose your roll number is MC432198765. Here we refer 8765 as last four digits of your roll number.

Question No. 1:                                         5 Marks

Write and execute the following Assembly language program on your system and tell what will be the value of BX register at the end of this program?

[org 0x0100]
Mov bx, 0x8765
Ror bx,8
mov ax, 0x4c00
int 0x21

Note: In above program 8765 is used as an example. You have to put last four digits of your roll number there.


Let us suppose the last four digits of your rollno. is 1234 then 

Answer: will     3412

only interchange the last two digit with the first two digits.

example:    abcd   then   cd  will come before  ab  as   cdab


Question No. 2:                                         5 Marks

Modify the above program such that at the end of your program, we shall have 1’s compliment of your roll number’s last four digits in BX register.
[org 0x0100]

Mov bx, 0x8765--------Please enter your roll number’s last four digits here
Not bx
mov ax, 0x4c00
int 0x21


Question No. 3:                                          10 Marks

Write an assembly language program that will calculate the number of 1’s in the binary representation of last four digits of your roll number. For example if the binary representation of last four digits of your roll no. is 1101001100001 then the number of 1’s will be 6. The total number of 1’s should be stored in AX register. In this case, AX will contain 6 at the end of program.


[org 0x0100]


     mov dx, 0x8765--------Please enter your roll number’s last four digits here
     mov cl, 17
     mov ax,0

a:
     shr dx, 1
     dec cl
     jz t
     jnc a

     add ax,1

    
      
     jnz a
t:

     mov ax, 0x4c00
     int 0x21

Wednesday, November 2, 2011

Assignment No. 01 CS401: Computer Architecture and Assembly Language Programming Semester: Fall 2011

Question No. 1:

a. Suppose architecture A has 14-bit address bus. What is maximum size of memory that can be accessed in this architecture? (Show the steps for calculating maximum accessible memory) (5 marks)


Memory accessed = 2 no. of bits
214 =16384
16384/1024 = 16KB


b. An architecture B has a maximum limit of 2GB memory. How many address bits are required for this architecture? (Show the steps for calculating required number of address bits) (5 marks)

2GB*1024=2048 MB
2048*1024=2097152 KB
2097152*1024=2147483648 Bytes
No. of bits = log2 (2147483648)
No. of bits = 31 bits


Question No. 2:
What are the first and the last physical memory addresses accessible using the following segment values? (2 mark each)
  1. 0000
First address = 00000 + 00000 =00000
Last  address = 00000 + 0FFFF =0FFFF
  1. FFFF
First address = FFFF0 + 00000 = FFFF0
Last address  = FFFF0 + 0FFFF = 0FFEF


Question No. 3:

Calculate physical address using the following segment offset pairs.
(1 mark each)
  1. ABCD:1234  = ABCD0 + 01234 =   ACF04
  2. 1234:ABCD  = 12340 + 0ABCD =   1CF0D






Question No. 4:

What is effective address generated by the following instructions? Every instruction is independent of others. Initially BX = 0xFF00, SI=0x00FF
(1 mark each)

  1. mov ax, [BX+SI]
   BX+SI =0xFF00 + 0x00FF = 0XFFFF

  = 0XFFFF

  1. mov ax, [BX+1024] (1024 is in decimal)
   BX+1024=0xFF00 + 0X400 = 0x0300

    = 0x0300






Question No. 5:

What are the contents of memory locations 720, 721, 722 and 723 if the word 4321 is stored at offset 720 and the word 8765 is stored at the offset 722 using Big Endean format? (2 marks)


Address
Contents

0x720
43
0x721
21
0x722
87
0x723
65