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