169 похожих чатов

Добрый вечер. Подскажите пожалуйста что нужно исправить. По заданию нужно

найти наибольшее по модулю значение элемента массива. У меня удалось осуществить только поиск наибольшего значения. Что нужно исправить ? NASM x86. Код:

section .data

array:
dd 3,67,34,222,45,75,54,34,44,33,22,11,66,0

section .text
global _start

_start:
mov edi, 0 ; set the index to 0
mov eax, [edi * 4 + array] ; set eax to the first element
mov ebx, eax ; set the max to the first element to start with

start_loop:
cmp eax, 0 ; see if we're at the last element, 0
je loop_exit ; if we are, jump to the loop exit
inc edi ; increment the index
mov eax, [edi * 4 + array] ; set the current element to the new element
cmp eax, ebx ; compare eax to ebx
jle start_loop ; if the new element is less than the max, continue the looping
mov ebx, eax ; otherwise set the new max to the current element
jmp start_loop ; whether or not we executed the previous instruction, we
; still need to go back to the beginning of the loop

loop_exit: ; return the max element using the exit system call
mov eax, 1 ; set the system call to exit (1)
int 80h ; ebx is already set to the max element

6 ответов

1 просмотр

Тут числа положительные все, какие модули?

Короче, я бы инициализировал ebx нулём, а не первым элементом, чтобы два раза кусок с neg не писать. И ещё я бы заменил jle на jbe. И тут je вместо jne.

xor edi, edi xor ebx, ebx _loop: mov eax, [edi×4+array] test eax, eax jns _positive neg eax _positive: cmp eax, ebx cmova ebx, eax inc edi or eax, eax jne _loop ret array: dd 3, -67, -34, 222, -45, 75, 777, -443, 634, -666, 32, 0

r0binak- Автор вопроса
Saenro
xor edi, edi xor ebx, ebx _loop: mov eax, [edi×4+a...

О, а что делает инструкция cmova? тоже флаги устанавливает ?

можно избавиться от страшной строчки: edi×4+array... xor ebx, ebx mov esi, array _loop: lodsd and eax, eax jns _positive neg eax _positive: cmp eax, ebx cmova ebx, eax or eax, eax jne _loop ret array: dd 1,2,-3,-5,4,0

Похожие вопросы

Обсуждают сегодня

а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
TCodePointer = record cp: CodePointer; name: string; cnt: Integer; next: TCodePointerArray; // этот тип ещё неизвестен end; TCodePointerArray = array of ...
notme
9
Привет ) есть такой кусок кода, он считывает ini файл. my $conf = Config::IniFiles->new( -file => $ini_file ); if (!$conf) { $self->my_die('cannot_read_cfg', ...
Kolya lastname
7
Добрый день. Хочу сделать отрисовку по команде на панели. Почему-то рисуется только при втором вызове. С чем может быть связано, не подскажете? procedure TForm1.FormDblClick(...
Kirill Filippenok
20
Всем привет! Подскажите. Я написал приложение на Delphi 10.2 Tokyo под Windows 10. И передо мной стал вопрос о том чтобы сделать это приложение кроссплатформенным (под Linux и...
Дмитрий Завгородний
24
Блин, интересно, кто-нибудь когда-нибудь переписывал какую-нибудь игру с x86 на arm? Вообще, такое возможно?
Alan 🔝 Бэброу
13
why html and css is not standard? i mean why different browser has their own engine and styles and how them work to show result to end user?
Mr Thieves
6
Эх кто-то пришел и весь праздник испортил :( You need complex FBX scene importing setup to change things on import? good luck with that. You need navigation and pathfinding? g...
Serg Gini
5
Всем привет! Нужен совет от опытных. Переношу свой проект с Делфи 10.2 Токио на Лазарус 3.2 установленный через инсталлятор fpcupdeluxe-x86_64-win64. При импортировании проект...
Дмитрий Завгородний
7
Всем доброго дня! Подскажите может кто использовал связку Pagebuilder + Clientsetting. Сами параметры с типом pagebuilder в модуле Clientsetting работают нормально, можно такж...
Александр Добриков
12
Карта сайта