Skip to main content

CS401 Assignment#1 Solution Spring 2018



Assignment No. 1 Graded

Semester Spring 2018

Computer Architecture and Assembly Language Programming– CS401


Total Marks: 15 Due Date: 10/05/2018






Question: 1                                                                                                                                       [15 Marks]


You will write a program to find the sum of even and odd digits of your VU id, You will store the sum of even digits in AX and sum of odd digits in BX register.
For example, If your VU id is bc123456789 you will use two arrays as 2,4,6,8
1,3,5,7,9


Then save the sum of first array in AX and second array in BX in hexadecimal format.

Explain each instruction of program in comments and also provide/paste snapshot of your assembled and debugged program result which will be run in AFD (A Full Screen Debugger) window showing the executed code and final result i.e. value in AX.

You will submit code and two screen shots in word file.

First screenshot will contain the command to compile the code Second screenshot will contain the final values in AX and BX
Note 1: You will use conditional jumps to solve the above problem. Marks will not be awarded for using any other approach.

Note 2: keep name of assembly file according to your VU id , i.e. if your VU id is BC123456789 , you will keep name of the assembly code file as 23456789.asm i.e. you will use last 8 digits of your id for the code file name.

Note 3: If the arrays, files names in the screen shots will not be according to your VU id you will get zero marks.

Note 4: No need to include alphabet part of your id in array. i.e. if your id is BC123456789 you will use 123456789 to make the arrays , you will ignore the BC part.


Example Run
Let say your id is BC123456789 , You will use two array as shown below, Array 1 : 2,4,6,8 ,
Array 2 : 1,3,5,7,9

Your first screen shot will look like this



Your final screen shot will be like shown below AX and BX conataing the sum of even and odd digits in your VU id in HEX format.



If you have 64bit version OS and you are using DOXBOX then your screen shots should look like this




Your 2nd screen shot will be like shown below AX and BX conataing the sum of even and odd digits in your VU id in HEX format





CS401 Assignment Solution





jmp start ; set control on start label.
Arr1: dw 7H,3H,5H ; Decleration of odd array.
Arr2: dw 3h,2h,0h ; Decleration of even array including 0. start: ; Start label
mov bx, 0 ; Set bx value 0 mov ax, 0 ; set ax value 0
mov cx,3 ; Set counter to 3 because our odd array length is 3 top1: ; A label for loop iterations.
cmp cx, bx ; compaire if counter is 0
jne even ; set control to even label if counter is not 0 even:   ; Even label
add ax,[Arr1+bx] ; Adding odd array elements one by one add bx,2 ; increasing array index number
loop top1 ; set control back to loop1 label.
mov dx,ax ; store ax value which is the sum of odd array elements. mov bx, 0 ; set back bx to 0
mov  ax, 0 ; set back ax to 0
mov cx,3 ; set counter again to 3 top2: ; a lebel for loop
cmp cx,bx ; compairing counter value if it is 0 jne odd ; jum on add label if not equal to 0 odd: ; odd label
add ax,[Arr2+bx] ; adding even array elements one by one add bx,2 ; increasing Array index number
loop top2 ; set control back to loop2 mov bx,ax ; store ax value in bx

mov ax,dx ; getting back value from dx mov dx,0 ; set dx to 0
INT 21h ; Return control to OS



OR


[org 0x0100]
jmp start
message: db 'your IDs'            ; string to be printed
length: dw 20                        ; length of string
clrscr: push es
push ax
push cx
push di
mov ax, 0xb800
mov es, ax                          ; point es to video base
xor di, di                          ; point di to top left column
mov ax, 0x0720                      ; space char in normal attribute
mov cx, 2000                        ; number of screen locations
cld                                 ; auto increment mode
repstosw                            ; clear the whole screen

pop di
pop cx
pop ax
pop es
ret

; subroutine to print a string
; takes the x position, y position, attribute, address of string and
; its length as parameters

printstr: push bp
mov bp, sp
push es
push ax
push cx
push si
push di
mov ax, 0xb800
mov es, ax                        ; point es to video base
mov al, 80                        ; load al with columns per row
mul byte [bp+10]                  ; multiply with y position
add ax, [bp+12]                   ; add x position
shl ax, 1                         ; turn into byte offset

mov di,ax                         ; point di to required location
mov si, [bp+6]                    ; point si to string
mov cx, [bp+4]                    ; load length of string in cx
mov ah, [bp+8]                    ; load attribute in ah
cld                               ; auto increment mode

nextchar: lodsb                   ; load next char in al
stosw                             ; print char/attribute pair
loopnextchar                      ; repeat for the whole string
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 10

start: call clrscr                ; call the clrscr subroutine
mov ax, 10
push ax                           ; push x position
mov ax, 15
push ax                           ; push y position
mov ax, 0x12                      ; blue on black attribute
push ax                           ; push attribute
mov ax, message
push ax                           ; push address of message
push word [length]                ; push message length
callprintstr                      ; call the printstr subroutine
mov ax, 0x4c00                    ; terminate program
int 0x21

Comments

Post a Comment

Popular posts from this blog

cs302 Solved Quiz

estion # 1 of 10 ( Start time: 03:03:55 PM )  Total Marks: 1    Divide-by-32 counter can be acheived by using   Select correct option:   Flip-Flop and DIV 10  Flip-Flop and DIV 16   Flip-Flop and DIV 32  DIV 16 and DIV 32 Question # 2 of 10 ( Start time: 03:05:20 PM )  Total Marks: 1   The counter states or the range of numbers of a counter is determined by the formula. (“n” represents the total number of flip-flops)   Select correct option:   (n raise to power 2)  (n raise to power 2 and then minus 1)  (2 raise to power n) (2 raise to power n and then minus 1) Question # 3 of 10 ( Start time: 03:06:36 PM )  Total Marks: 1   A 4- bit UP/DOWN counter is in DOWN mode and in the 1010 state. on the next clock pulse, to what state does the counter go?   Select correct option:   1001  1011  0011  1100 Question # 4 of 10 ( Start time: 03:07:37 PM )  Total Marks: 1   A 4-bit binary UP/DOWN counter is in the binary state zero. the next state in the DOWN mode is

Mth621 Final term paper sept 2020

  Mth 621 paper Practise queation ma sa 80% aya : 3nu quizes ma sa sary mcqs ay Objective bi 30 aur subjective bi 30 k tha total 60 marks k paper tha Subjective total chap3 aur chap 4 ma say tha Subjective almost practise question ma sa tha Mcqs 80% quizes ma sa thay G therorem bi aik 2 to zehn ma ni a rhy 621 theorem on bounded set theorem on reman integral mean value theirem limit chain rule integaration 621 k saare mcq old quizes m se aye #Mth621 Mcqs were based on concepts and 6,7 was from mcqs file of quizz. 1-Define Removeavle continuity? 2 marks 2-Deifine chain rule for composition of functions? 2 marks 3-Define Second mean theorem of Integration? 4- Find uniform continuity of 2x? 5- A theorem was from Monotonic Function? 5 marks 6-evaluate lim->0 ln sinx/ln x?? 7- and Rest two was from the last 5th chp of about integration on closed interval. Mcqs zyada quiz mai sy thy evaluate lim->0 ln sinx/ln x?? Find uniform continuity of 2x? generalized mean value the

UniVERSITY VIRTUAL CAMPUSES & Contact #

UniVERSITY VIRTUAL CAMPUSES VU OWN CAMPUSES Sr # Province City Code Details 1    BALOCHISTAN PISHIN VPSN01 Virtual University Campus, Pishin Killi Malik Abdul Razzaq, Pishin Phone:   0826-442275 Fax:   - Email:   vpsn01@vu.edu.pk ,   vpsn01@vu.edu.pk   2    CAPITAL ISLAMABAD VIBD01 Virtual University Campus, Islamabad 9-E, Rizwan Plaza, Blue Area, Islamabad. Phone:   051-9213476 Fax:   NA Email:   vibd01@vu.edu.pk ,   vibd01@vu.edu.pk   3    KHYBER-PAKHTUNKHWA PESHAWAR VPSW01 Virtual University Campus, Peshawar 8-Jamrud Road, P.O. Tehkal Bala, Adjacent Toyota Froniter Motors, Peshawar. Phone:   091-5701071, 5705994 Fax:   091-5711381 Email:   vpsw01@vu.edu.pk ,   vpsw01@vu.edu.pk   4    PUNJAB D.G. KHAN VDGK01 Virtual University Campus, D.G. khan Sakhi Sarwar Road, Old D.D.A. Building, Near Pul Dat, D.G. Khan. Phone:   064-2000919, 2472813 Fax:   - Email:   vdgk01@vu.edu.pk ,   vdgk01@vu.edu.pk