<> On branch structure

Branching of programs is very common , This article will discuss the branch structure in the compilation through a question .

<> subject

* Program execution is , Display prompt information “Please input a string (length<9):”, Enter a length less than 9 String of ;
* The prompt message is then displayed “Please input the index of the char to
display”, Ask the user to specify the location number of a string in the string , Program control user input location number must be legal ; If it is illegal, the program exits
* The program displays the string at the location specified by the user
Output example 1
Please input a string (length < 9):ABCDEFG Please input the index of the char
to display :2 The char is:C
Output example 2
Please input a string (length < 9):ABC Please input the index of the char to
display :4 The index is invalid!
<> code

First, the whole code
data SEGMENT strmess db 'Please input a string(length < 9):$' strtoolong db
0ah,0dh,'The string is too long!$' nummess db 0ah,0dh,'Please input the
number(index < 4) of the char to display:$' charmess db 0ah,0dh,'the char is
:$' chartoolong db 0ah,0dh,'The index is invaild!$' buf db 10,?10 dup(0) num
db ? data ENDS ;description code SEGMENT USE16 assume cs:code,ds:data start:mov
ax,data mov ds,ax lea dx,strmess mov ah,09h int 21h lea dx,buf mov ah,0ah int
21h cmp buf+1,8 jg strlong jle strnext strlong: lea dx,strtoolong mov ah,09h
int 21h mov ax,4c00h int 21h strnext: lea dx,nummess mov ah,09h int 21h mov
ah,01h int 21h sub al,30h mov num,al cmp buf+1,al jle charlong jg charnext
charlong: lea dx,chartoolong mov ah,09h int 21h mov ax,4c00h int 21h charnext:
lea dx,charmess mov ah,09h int 21h mov bl,num mov bh,0 mov dl,buf[bx+2] mov
ah,02h int 21h mov ax,4c00h int 21h code ENDS END start
* Operation results

<> analysis

This topic needs to be used first 10 Call to get user input , By judging whether the string exceeds 8 To make a jump branch , If more than 8, Then output the error message and end the program , If it is correct, it should be continued .

* adopt cmp To return a value , Reuse jump To jump
* sub al,30h reason why al Need to reduce 30h, Because 1 The No. call accepts the character input by the user ASCII code , and 0~9 Plastic surgery and ASCII The code is exactly different 30.
<> Branching structure
Created with Raphaël 2.2.0 start My operation Jump command end yes no
Several examples of jump instructions

Instruction synonymous jump condition
jejz equal
jgjnle greater than
jljnge less than
<> summary

This program can also be added loop loop , When the user input is illegal , Continue until the input is correct . Compilation of a rookie , If there is a mistake or a better way, please point it out in the comments section , Welcome to discuss .

©2019-2020 Toolsou All rights reserved,
python3 Of tkinter Design of login interface +mysql Import data of database A magic lossless compression experiment to shake “ information theory ”!!!【Java Details of knowledge points 3】 Serializable and Deserialize What is polymorphism ? What is the mechanism to achieve polymorphism ?【 Le Bo TestPro】 Force button 416. Dividing equal sum subsets knapsack problem 【 Data structure and algorithm 13】 Binary tree Smart screen and smart wearable development : Component method Model 2 Addition, subtraction, multiplication and division of operations C++ realization 《 Labyrinth 》 Games 【 Data structure and algorithm 8】 The maze problem of recursion