What is the nop for here?
Why is there nop
in this tutorial code? The code changes lowercase letters to uppercase letters.
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
There are several reasons to insert a NOP into the code. One of them is to adjust the size of the program to the desired size, 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 operation of the conveyor. To ensure correct unconditional transitions, and to make the branch predictor less obtuse, a nop is inserted, in case the predictor is wrong. In case of an error, it will do nothing. With manual operation when coding in assembly language, there is no point in doing this. This is short, because you can get a more detailed answer if you understand the architecture of the processor well. Nop is also often used for debugging. You don't need it in your code.
I can assume that:
- This is the place where you can put the "breakpoint" or "transition to the debugger" instruction in an already running program.
- A place where you can put a RET to make a stub out of the procedure.
NOP is a "no operation" statement, i.e. it does nothing. Not formally needed.