1 / 18

Array Addition

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. Data Segment. section .data cntmsg db 10, 'Enter Count of the array element (Two Digit)::', 0x0a cntmsg_len equ $-cntmsg

lamya
Download Presentation

Array Addition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. Data Segment

  3. 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

  4. BSS Section

  5. section .bss num_ascii resb 03 cnt resb 01 res_l resb 01 res_h resb 01 num_buff resb 04

  6. Display Macro

  7. %macro dispmsg 2 mov eax,04 mov ebx,01 mov ecx,%1 mov edx,%2 int 80h %endmacro

  8. Accept Macro

  9. %macro accept 2 moveax,03 movebx,0 mov ecx,%1 mov edx,%2 int 80h %endmacro

  10. Text Section

  11. 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

  12. Accept array

  13. ;********** 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

  14. ;*************** 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

  15. PackNum

  16. ;********************** 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

  17. Display Procedure

  18. 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

More Related