Why in this training code nop ? The code changes the lowercase letters to uppercase.

 DATASG SEGMENT PARA MYTEXT DB 'Our Native Town',13,10,'$' DATASG ENDS STACKSG SEGMENT 'Stack' DB 12 DUP(?) STACKSG ENDS CODESG SEGMENT PARA 'Code' BEGIN PROC FAR ASSUME SS:STACKSG,CS:CODESG,DS:DATASG PUSH DS SUB AX,AX PUSH AX MOV AX,DATASG MOV DS,AX LEA BX,MYTEXT MOV CX,10H MT1: MOV AH,[BX] CMP AH,61H JB MT2 CMP AH,7AH JA MT2 CALL COR MT2: INC BX LOOP MT1 LEA DX,MYTEXT MOV AH,09H INT 21H RET BEGIN ENDP COR PROC NEAR NOP AND AH,0DFH MOV [BX],AH RET COR ENDP CODESG ENDS END BEGIN 

    3 answers 3

    There are several reasons to embed NOP code. One of them is to adjust the size of the program to the one you need, so that, say, it takes up a certain amount of memory. The second is the alignment of the addresses of the commands that are executed (for optimization). The most common reason is to improve the work of the conveyor. To provide the correct unconditional jumps, and so that the branch predictor is less stupid, nop is inserted, in case the predictor is wrong. In case of an error, he will not do anything. When hand-coding in assembler, there is no point in doing this. This is short, because you can get a more detailed answer if you understand the processor architecture well. Another nop is often used for debugging. It is not needed in your code.

      I can assume that:

      1. This is the place where you can put a "breakpoint" or "switch to a debugger" instruction in an already running program.
      2. A place where you can put RET to make a stub out of the procedure.

        NOP is a non-operation instruction, i.e. it does nothing. Formally not needed.