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
please guide cs401 assignment
ReplyDeleteOepcocbel-ji Adam Smallwood https://wakelet.com/wake/TId09SEATLZN6tLSPEAOp
ReplyDeletesilourrasi