M
M
Muriam2019-02-16 17:58:56
assembler
Muriam, 2019-02-16 17:58:56

Where does the debugger show that the maximum array element is 9 in this program?

There is a program code. It correctly calculates the maximum element of the array, which should be = 9.
But when debugging in TASM, I do not understand where this value 9 is written

TITLE Program3		;название программы
.MODEL small		        ;отводим под стек и под данные по 64Кб
.STACK 100h			;отмечаем начало сегмента стека
.DATA				;отмечаем начало сегмента данных
A DW 5, 3, 9, 4, 5	        ;описание массива из 5 элементов
Max DW 0			;описание переменной Max
.CODE				;отмечаем начало сегмента кодов

main PROC
mov AX, @data		;копируем адрес
mov DS, AX			;сегмента данных
mov SI, OFFSET A	        ;заносим в SI начало массива А
mov CX, 4			;в СХ заносим количество итераций
cld					;устанавливаем прямой порядок обработки массива
mov AX, [SI]
mov Max, AX			;в Мах заносим первый элемент массива

L1:					
inc SI				;сдвигаемся по массиву к следующему
inc SI				;элементу
mov AX,[SI]			;заносим в АХ текущий элемент массива
cmp AX, Max			;сравниваем АХ с Мах
jbe L2				;если меньше или равно, переходим на L2
mov Max, AX			;иначе запоминаем новый максимум

L2:					
loop L1				;циклически повторяем все действия

mov AX,4C00h		        ;выход
int 21h				;из программы
main ENDP
END main

my Debug Result:
5c68246708a3d073253233.png
Debug Result. which should turn out. but why can't it work for me?
5c6825baa5ce5632002143.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-02-16
@Muriam

Why, when debugging (picture 1), and when debugging someone else (picture 2), in the segment below, where there are four lines es, the values ​​​​are completely different, although this is debugging the same program?

Maria , because the memory is filled by and large with garbage. es is not initialized in your program, it is not clear why you are looking at it. You have to look at ds. In your debugger, Max is located at 57ef:000a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question