Compilation-count male and female students

Source: Internet
Author: User
Zookeeper

I. Internship questions:Count the number of male and female students


II. Purpose:Master the basic methods of loop design


III. Internship content:

Count the number of male and female in a 10-member class. Store the number of boys in the variable MAN and the number of girls in the variable WOMAN.

Tip: male and female can use the '1' and '0' characters as the logo and enter the logo from the keyboard. You can sum up the input flags by category.


4. Code:

Data segment men db '1'; boys are 1 women db '0'; girls are 0 menNum db '0'; boys are womenNum db '0 '; female: MsgOne db 0dh, 0ah, 'Men num is: ',' $ 'MsgTwo db 0dh, 0ah, 'the women num is :', '$ 'data endscode segment assume DS: data, CS: codestart: mov ax, data; mov DS, ax; mov cx, 10; count: mov ah, 01 h; enter an int 21 h cmp al and men. If the input is '1', jz addMen is a boy. If the input is a boy, the number of boys + 1 Code place jnz one is displayed; otherwise, determine whether it is a girl one: cmp al, women. If the input character is '0', it is the girl jz addWomen; jump to the number of girls + 1 Code place jnz two; addMen: inc menNum; boys plus 1 jmp next; addWomen: inc womenNum; girls plus 1 jmp next; two: inc cx; next: loop count; lea dx, MsgTwo; mov ah, 09 h; int 21 h; mov dl, womenNum; mov ah, 02 h; int 21 h; lea dx, MsgOne; mov ah, 09 h; int 21 h; mov dl, menNum; mov ah, 02 h; int 21 h; mov ah, 4ch; int 21 h; code endsend start

V. Running result:


Note: This program will end only when you enter '0' or '1' ten times. Other characters entered are invalid.

Compilation-count male and female students

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.