CS401 Assignment 1 Solution Spring 2021
[org 0x0100]
jmp begin
VU_ID: dw 1, 8, 0, 2, 0, 0, 1, 1, 6 ; array - consecutive memory locations (2 bytes per index)
sum: dw 0 ; variable
; mnemonic destination, source
begin: mov ax, 0 ; the result of addition will be stored in the AX register
mov bx, VU_ID ; address will be stored in the BX register
mov cx, 9 ; the count of nine digits will be stored in the CX register
; 0 - 0 == 0
continue_Process: cmp word [bx], 0 ; non-destructive subtraction in other words, the result of subtraction does not store anywhere but this result
; is used to set the flags only
je check_Is_Entire_Array_Traversed ; if the value of index is equal to zero then jump (conditional jump)
add ax, [bx] ; add index's value to the AX register's value
check_Is_Entire_Array_Traversed: add bx, 2 ; move to the next index (remember this is a address)
sub cx, 1 ; decrement our count
jnz continue_Process ; continue process if the entire is not traversed
mov [sum], ax ; total sum is stored in variable
terminate: mov ax, 0x4c00 ; ending instructions
int 0x21
0 Comments