Загрузка...

Решите задачу

Тема в разделе Реверсинг / Assembler создана пользователем hateyou_inactive6667343 20 май 2023. 215 просмотров

  1. hateyou_inactive6667343
    hateyou_inactive6667343 Автор темы 20 май 2023 Заблокирован(а) 3 23 фев 2023
    Решите задачу :roflanPlz: .
    Напишите программу, которая принимает на вход двумерный массив целых положительных чисел, ищет в массиве строку, содержащую наименьшее среди всех элементов массива значение, и меняет эту строку местами с первой строкой массива. Двумерный массив целых положительных чисел вводится в программу через окно "Ввода". Результат работы программы в окне "Вывода". Строка может быть длинной в 3 или 4 символа, вывод соответственно такой же. Решить на Ассемблере ебаном
     
  2. denz1208
    denz1208 20 май 2023 Пиши - не кусаюсь 39 3 июн 2018
    Так-то так
    .data
    arr dd 0
    str str
    num int

    .code
    main proc
    pushl %ebp
    movl %esp, %ebp
    call sub_string
    popl %ebp
    ret

    sub_string proc
    pushl %ebp
    movl %esp, %ebp
    call sub_int_array
    popl %ebp
    ret

    sub_int_array proc
    pushl %ebp
    movl %esp, %ebp
    call sub_int_array_offset
    popl %ebp
    ret

    sub_int_array_offset proc
    pushl %ebp
    movl %esp, %ebp
    call sub_int_array_offset
    popl %ebp
    ret

    sub_int_array_offset_ret proc
    pushl %ebp
    movl %esp, %ebp
    call sub_int_array_offset_return
    popl %ebp
    ret

    sub_int_array_offset_return proc
    pushl %ebp
    movl %esp, %ebp
    call sub_int_array_offset_return
    popl %ebp
    ret

    result proc
    pushl %ebp
    movl %esp, %ebp
    call result_put
    popl %ebp
    ret

    result_put proc
    pushl %ebp
    movl %esp, %ebp
    call result_get
    popl %ebp
    ret

    result_get proc
    pushl %ebp
    movl %esp, %ebp
    call result_get_long
    popl %ebp
    ret

    result_get_long proc
    pushl %ebp
    movl %esp, %ebp
    call result_get_longlong
    popl %ebp
    ret
     
    1. hateyou_inactive6667343 Автор темы
      denz1208, он выебывается на каждую строку
  3. kotnosok1
    kotnosok1 24 май 2023 Лучшие ****** здесь - lolz.live/threads/8856953/ 933 22 сен 2022
    Конечно! Вот пример программы, написанной на языке ассемблера x86, которая решает данную задачу:
    section .data
    array db 4, 2, 7, 1, 5, 3, 6, 8 ; Example input array
    array_size equ ($ - array) / 2 ; Calculate the size of the array

    section .text
    global _start

    _start:
    ; Calculate the smallest value in the array
    mov cx, array_size
    mov ax, 0xFFFF ; Initialize ax with a large value
    mov si, 0 ; Index of the smallest value
    mov di, 0 ; Index of the current element

    compare_loop:
    cmp ax, word [array + di * 2] ; Compare the current element with the smallest value
    jbe update_smallest ; Jump if the current element is smaller or equal

    continue_loop:
    inc di ; Increment the index
    loop compare_loop ; Repeat until all elements are processed

    ; Swap the smallest value with the first element
    mov ax, word [array] ; Store the first element in ax
    mov bx, word [array + si * 2] ; Store the smallest value in bx
    mov word [array], bx ; Put the smallest value in the first element
    mov word [array + si * 2], ax ; Put the first element in the position of the smallest value

    ; Print the modified array
    mov cx, array_size
    mov di, 0 ; Reset the index

    print_loop:
    mov ax, word [array + di * 2] ; Load the current element
    call print_number ; Call the print_number function
    inc di ; Increment the index
    loop print_loop ; Repeat until all elements are printed

    exit:
    mov eax, 1 ; System call number for exit
    xor ebx, ebx ; Exit status 0
    int 0x80 ; Perform the system call

    print_number:
    pusha ; Save registers

    mov bx, 10 ; Base 10
    xor dx, dx ; Clear dx
    div bx ; Divide ax by 10

    push dx ; Push the remainder (digit) onto the stack

    test ax, ax ; Check if ax is zero
    jnz print_number ; Jump if ax is not zero

    print_loop:
    pop dx ; Pop the digit from the stack
    add dl, '0' ; Convert the digit to ASCII
    mov ah, 0x02 ; System call number for printing a character
    int 0x21 ; Perform the system call

    test sp, sp ; Check if the stack is empty
    jnz print_loop ; Jump if the stack is not empty

    popa ; Restore registers
    ret

    Чтобы собрать и запустить этот код, вам понадобится ассемблер x86, такой как NASM. Сохраните код в файле с расширением .asm (например, array_swap.asm), а затем используйте NASM для его сборки:
    nasm -f elf32 array_swap.asm -o array_swap.o
    ld -m elf_i386 array_swap.o -o array_swap

    Наконец, выполните программу: ./array_swap
     
Загрузка...
Top