Array Addition - WordPress.com
Download
Report
Transcript Array Addition - WordPress.com
MICROPROCESSOR ARCHITECTURE
UOP S.E.COMP (SEM-II)
ARRAY ADDITION
Prof.P.C.Patil
Department of Computer Engg
Matoshri College of Engg.Nasik
[email protected].
DATA SEGMENT
section .data
cntmsg db 10,'Enter Count of the array element (Two Digit)::',0x0a
cntmsg_len equ $-cntmsg
nummsg db 10,'Enter Number(s)(Two Digit) ::',0x0a
nummsg_len equ $-nummsg
resmsg db 10,'Addition of array elements is ::',0x0a
resmsg_len equ $-resmsg
newline db 10
newline_len equ $-newline
BSS SECTION
section .bss
num_ascii resb 03
cnt resb 01
res_l resb 01
res_h resb 01
num_buff resb 04
DISPLAY MACRO
%macro dispmsg 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 80h
%endmacro
ACCEPT MACRO
%macro accept 2
mov eax,03
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro
TEXT SECTION
dispmsg cntmsg,cntmsg_len
;ENTER COUNT OF NUMBER
accept num_ascii,3
;ACCEPT COUNT FROM USER (IN ASCII FORM)
call packnum
;CALL packnum TO CONVERT ASCII INTO
NUMBER
mov [cnt],bl
;MOVE ACCEPTED COUNT INTO cnt VARIABLE
xor rcx,rcx
mov cl,[cnt]
;INITIALISE RCX TO 0
;MOVE COUNT INTO CL
ACCEPT ARRAY
;********** PROCEDURE TO ACCEPT & ADD ARRAY ELEMENT *******
addition:
push rcx
dispmsg nummsg,nummsg_len
;ENTER THE ARRAY ELEMENT
accept num_ascii,3
;ACCEPT ARRAY ELEMENT (IN ASCII FORM)
call packnum
;CONVERT ASCII INTO NUMBER
add [res_l],bl
;ADD NUMBER INTO RES_L AS LOWER BYTE
adc byte [res_h],0
;ADD WITH CARRY RES_H AS HIGHER BYTE
pop rcx
;POP RCX TO DECREMENT COUNT
loop addition
;REPEATE ADDITION PROCESS UNTIL CL=0
;*************** DISPLAY ADDITION ***************
dispmsg resmsg,resmsg_len
mov bl,[res_l]
mov bh,[res_h]
call disp16_proc
;ADDITION OF ARRAY ELEMENT IS
dispmsg newline,newline_len
;ENTER THE ARRAY ELEMENT
mov eax,01
mov ebx,00
int 80h
;Exit PROGRAM
;MOV LOWER BYTE INTO BL TO PRINT
;MOV HIGHER BYTE INTO BH TO PRINT
;CALL DISPLAY PROCEDURE TO DISPLAY
ADDITION
PACKNUM
;********************** packnum **********************
packnum:
mov bl,0
mov ecx,02
mov esi,num_ascii
up2:
rol bl,04
mov al,[esi]
cmp al,39h
jbe skip2
sub al,07h
skip2: sub al,30h
add bl,al
inc esi
loop up2
ret
;INITIALISE BL BY 0
;INITIALIZE COUNTER AS 02
;POINT ESI TO num_ascii
;ROTATE BL TO LEFT
;MOV NUMBER INTO AL
;COMPARE AL(NO IN ASCII) WITH 39H
;JUMP IF LESS THAN 39
;SUB 07 IF num_ascii>39
;SUB 30 IN BOTH CASES
;ADD PREVIOUS NO INTO CURRENT
;INCREMENT ESI
;RPEATE LOOP
DISPLAY PROCEDURE
disp16_proc:
;---------------------mov bx,[num] ;STORE NUMBER IN BX ---------------------mov esi,num_buff
;POINT ESI TO NUM_BUFFER
mov ch,04
mov cl,04
;LOAD NUMBER OF DIGITS TO DISPLAY
;LOAD COUNT OF ROTATION IN CL
rol bx,cl
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jbe skip1
add dl,07h
;ROTATE NUMBER LEFT BY FOUR BITS
;MOVE LOWER BYTE IN DL
;MASK UPPER DIGIT OF BYTE IN DL(GET ONLY LSB)
;ADD 30H TO CALCULATE ASCII CODE
;COMPARE WITH 39H
;IF LESS THAN 39H AKIP ADDING 07 MORE
;ELSE ADD 07
mov [esi],dl
inc esi
dec ch
jnz up1
;STORE ASCII CODE IN DNUM_BUFFER
;POINT TO NEXT BYTE
;DECREMENT THE COUNT OF DIGITS TO DISPLAY
;IF NOT ZERO JUMP TO REPEAT
dispmsg num_buff,8
;CALL TO MACRO
up1:
skip1:
ret