190 likes | 299 Views
This document provides an overview of implementing array addition using microprocessor architecture in assembly language. It covers key concepts such as data segment operations, user input handling, ASCII to number conversion, addition procedures, and displaying results. The example code illustrates how to accept the count of array elements, perform the addition of two-digit numbers, and output the final result. Students in the second semester of the Computer Engineering program at Matoshri College will find this practical implementation guide helpful for understanding assembly language operations.
E N D
Microprocessor Architecture UOP S.E.Comp (Sem-II) • Array Addition Prof.P.C.Patil Department of Computer Engg Matoshri College of Engg.Nasik pcpatil18@gmail.com.
section .data cntmsg db 10,'Enter Count of the array element (Two Digit)::',0x0a cntmsg_len equ $-cntmsg nummsgdb 10,'Enter Number(s)(Two Digit) ::',0x0a nummsg_len equ $-nummsg resmsg db 10,'Addition of array elements is ::',0x0a resmsg_len equ $-resmsg newlinedb 10 newline_len equ $-newline
section .bss num_ascii resb 03 cnt resb 01 res_l resb 01 res_h resb 01 num_buff resb 04
%macro dispmsg 2 mov eax,04 mov ebx,01 mov ecx,%1 mov edx,%2 int 80h %endmacro
%macro accept 2 moveax,03 movebx,0 mov ecx,%1 mov edx,%2 int 80h %endmacro
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 ;INITIALISE RCX TO 0 mov cl,[cnt] ;MOVE COUNT INTO CL
;********** PROCEDURE TO ACCEPT & ADD ARRAY ELEMENT ******* addition: push rcx dispmsgnummsg,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 *************** dispmsgresmsg,resmsg_len;ADDITION OF ARRAY ELEMENT IS mov bl,[res_l] ;MOV LOWER BYTE INTO BL TO PRINT mov bh,[res_h] ;MOV HIGHER BYTE INTO BH TO PRINT call disp16_proc ;CALL DISPLAY PROCEDURE TO DISPLAY ADDITION dispmsg newline,newline_len ;ENTER THE ARRAY ELEMENT mov eax,01 ;Exit PROGRAM mov ebx,00 int 80h
;********************** packnum ********************** packnum: mov bl,0 ;INITIALISE BL BY 0 mov ecx,02 ;INITIALIZE COUNTER AS 02 mov esi,num_ascii ;POINT ESI TO num_ascii up2: rol bl,04 ;ROTATE BL TO LEFT mov al,[esi] ;MOV NUMBER INTO AL cmp al,39h ;COMPARE AL(NO IN ASCII) WITH 39H jbe skip2 ;JUMP IF LESS THAN 39 sub al,07h ;SUB 07 IF num_ascii>39 skip2: sub al,30h ;SUB 30 IN BOTH CASES add bl,al ;ADD PREVIOUS NO INTO CURRENT inc esi ;INCREMENT ESI loop up2 ;RPEATE LOOP ret
disp16_proc: ;---------------------mov bx,[num] ;STORE NUMBER IN BX ---------------------- mov esi,num_buff ;POINT ESI TO NUM_BUFFER mov ch,04 ;LOAD NUMBER OF DIGITS TO DISPLAY mov cl,04 ;LOAD COUNT OF ROTATION IN CL up1: rol bx,cl ;ROTATE NUMBER LEFT BY FOUR BITS mov dl,bl ;MOVE LOWER BYTE IN DL and dl,0fh ;MASK UPPER DIGIT OF BYTE IN DL(GET ONLY LSB) add dl,30h ;ADD 30H TO CALCULATE ASCII CODE cmp dl,39h ;COMPARE WITH 39H jbe skip1 ;IF LESS THAN 39H AKIP ADDING 07 MORE add dl,07h ;ELSE ADD 07 skip1: mov [esi],dl ;STORE ASCII CODE IN DNUM_BUFFER inc esi ;POINT TO NEXT BYTE dec ch ;DECREMENT THE COUNT OF DIGITS TO DISPLAY jnz up1 ;IF NOT ZERO JUMP TO REPEAT dispmsg num_buff,8 ;CALL TO MACRO ret