calculate the 1+2+3+...+100 and
1 ;calculate the 1+2+3+...+100 and2DATA SEGMENT;Data segment Start3 SUM DW?4 DATA ENDS5 6CODE SEGMENT;Code Snippet Start7AssumeCS:CODE,DS:DATA8 START: MOVAx,data9 MOVDs,axTen XORAx,ax One MOVCX, - A NEXT: ADD, Ax,cx - LOOP NEXT - MOVSum,ax the MOVAh,4ch;4C function Call: Terminates the current program and returns the calling program - INT21H -CODE ENDS;end of code snippet -END;End of Assembler program
Determines whether the unsigned number in the variable num is a prime
Program Requirements:
Write a assembler that determines whether the unsigned number in the variable num is a prime, and if it is a prime, output the character p to the screen, and if it is composite, output c to the screen.
Where num is given in the data segment.
Program Flow:
Code implementation:
1 ;write a assembler to determine if the unsigned number in the variable num is a prime,2 ;If it is a prime number, output the character p to the screen, and if it is composite, output c to the screen. 3 ;where num is given a reference in the data segment4DATA SEGMENT;Data Segment5NUM DW -6 DATA ENDS7CODE SEGMENT;Code Snippet8AssumeCS:CODE,DS:DATA9 START: MOVAx,dataTen MOVDs,ax;send a segment base of data segment to DS One MOVSI,1 ;SI 16-bit source variable address pointer register A - Back : INCSI - XORAx,ax the XORDX,DX - MOVAx,num - CMPAx,si;Compare whether the divisor (NUM) and divisor (SI) are equal - JZPrint_p;JZ equals then jumps + DIVSI;a 32-digit number divided by 16-bit SI with DX and ax - CMPDx0 ;the remainder is inside the DX, judging whether the remainder is 0 + jnzBack;JNZ does not equal the jump A at Print_c:XORDX,DX - MOVClass'C' - MOVAH,2 - INT21H - JMPEXIT;JMP unconditional Jump instruction - in print_p:XORDX,DX - MOVClass'P' to MOVAH,2 + INT21H - the EXIT: MOVah,4ch * INT21H $ CODE ENDSPanax NotoginsengEND START
01_ assembly Language (Basic format _ template)