Jump to content
Papaitucano

Assembly dúvida

Recommended Posts

Papaitucano

Boas.

Tenho aqui um workzito para fazer mas que tá complicado, estou farto de mexer nisto mas algo aqui não bate certo  :wallbash:

Primeiro isto imprimia na horizontal mas lá consegui mudar... agora não me ordena alguns números... e o $$$$ considera outro número..

Não sei se alguém me pode ajudar, mas agradecia bastante... Ao menos que me tentem ensinar pois sou novo nisto.. Obrigado ;)

Cá vai...

O enunciado:

acso1.png

O pseudocódigo:

acso2.png

O que tenho...

includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

.data
   Tab dd 45,21,3,89,5,10,6,12,55,2345,5,'$$$$'
   Tab2 dd 1
.code                       ; Tell MASM where the code starts
   

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

  start:                          ; The CODE entry point to the program


    call main
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
main proc Near

inicio:

mov edi,1   ;buttom 0
mov esi,0   ;i do loop
mov ebp,10  ;L-1



do:
mov eax,1   ;swapped true


mov ecx,edi ;mover edi(buttom 0) para ecx
for1:
mov ebx,Tab[esi]
mov edx,Tab[esi+4]
cmp ebx,edx
jb naotroca

mov Tab[esi],edx
mov Tab[esi+4],ebx
mov eax,0  ;swapped false 

naotroca:
add esi,4 
loop for1

dec ebp  ;top=top-1
mov ecx,ebp
mov esi,ebp
imul esi,4


for2:
mov ebx,Tab[esi]
mov edx,Tab[esi-4]
cmp ebx,edx
ja naotroca2

mov Tab[esi],edx
mov Tab[esi-4],ebx
mov eax,0  ;swapped false 

naotroca2:
sub esi,4
loop for2

mov ebx,Tab2[0]
inc ebx
mov Tab2[0],ebx

cmp eax,0
je do

cmp edi,ebp
jb do


mov ecx,11
sair:
push ecx
print str$(Tab[esi])
print chr$(13,10)
add esi,4
pop ecx
loop sair

print chr$(13,10)
print str$(Tab2[0])
print chr$(13,10)


ret
main endp

Share this post


Link to post
Share on other sites
KTachyon

Os 4 chars irão ser colocados numa célula e irão ser interpretados como um inteiro.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
KTachyon

Bem, tu podes detectar esse valor. Os 4 chars ocupam 1 byte cada, totalizando 4 bytes, que é uma word, o mesmo espaço ocupado por um inteiro. Se converteres o texto de ASCII para binário podes depois converter para inteiro e saber o valor que estará nessa célula.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.