2 years ago

#51439

test-img

Born Ok

Copying of array to stack

I'm a new to assembly and have no idea why It does not push %EAX after end_while: instruction. I have to provide the implementation of the function with an example of a call to set the value of the largest 32-bit integer values in the array. A copy of the array (the values of all elements) and the result (the largest value) are passed through the stack.

.globl _start
.data
tab: .long 2, 100, 14, 3, 4, 2, 7 
end_tab:
    .equ tab_byte, end_tab - tab
    .equ tab_size, tab_byte/4
.text
prog:
    mov 4(%ESP), %ECX
    mov 8(%ESP), %EBX
    dec %ECX
    push (%EBX, %ECX, 4)
    mov (%EBX, %ECX, 4), %EAX
while:
    dec %ECX
    cmp $0, %ECX 
    jl end_while
    push (%EBX, %ECX, 4)
    cmp (%EBX, %ECX, 4), %EAX
    jl change
    jmp while 
change:
    mov (%EBX,%ECX,4), %EAX
    jmp while
end_while:
    push %EAX
    ret 
_start:
    push $tab
    push $tab_size  
    call prog
    nop

As a result I don't get what I expect from this stack meaning that I want to get the largest value following the last element on the stack.

0xffffd0e8:     2       100     14      3
0xffffd0f8:     4       2       7       134516786
0xffffd108:     7       134520832       1       -11565

arrays

assembly

att

stack-memory

0 Answers

Your Answer

Accepted video resources