01_ assembly Language (Basic format _ template)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.