Я новичок в сборке, и я пытаюсь сделать следующее:
псевдокод:
loop:
input
if(input == $)
end loop
else if(input < savedInput)
savedInput = input
;
print savedInput
в основном это постоянный цикл, который обнаруживает пользовательские вводы и сравнивает значение ASCII сохраненного ввода с новым вводом, если новый ввод ниже, то он заменяет сохраненный ввод. Если ввод равен $, то цикл завершается и печатается сохраненный ввод.
Это мой код
.MODEL SMALL
.STACK 100h
.DATA
insertMsg DB 13, 10, 'Introduce un dato: ', 13, 10, '$'
.CODE
main:
mov ax,@data
mov ds,ax ; Set DS to point to the data segment
mov dx,OFFSET insertMsg ; Point to the insertMsg
back:
mov ah,9 ; DOS: print string: Service 21h, 09h
int 21h ; Display inputMsg
mov ah,1 ; DOS: get character: Service 21h, 01h
int 21h ; Get a single-character response
cmp al,'$' ; if character equals $
je display ; goto display
loop back ; loop back
display:
mov ah,9 ;DOS: print string: Service 21h, 09h
int 21h ;display input
mov ah,4Ch ;DOS: terminate program: Service 21h, 4Ch
mov al,0 ;return code will be 0
int 21h ;terminate the program
end main
Проблема в том, что я не знаю, как сохранять и сравнивать значения ASCII
loop back
не является хорошим выбором в этом случае, вы хотите сделатьjmp back
, чтобы всегда прыгать туда,loop
не будет прыгать после того, какcx
станет равным нулю (и вы не определяетеcx
, поэтому вы зависите от среды запуска). Иloop
почти никогда не бывает хорошим выбором, если только вы не играете в гольф на размер кода, пара из инструкций:dec cx
jnz label
лучше для производительности на современных x86 CPU. - person Ped7g   schedule 29.10.2017jne back
вместо условного перехода вперед через безусловную ветвь цикла. - person Peter Cordes   schedule 30.10.2017