Question

i am new in assembly language.any how i am working on my home work.what i have to do is that i have to copy contents of 1st array into second array and then what i have to do is that to get the contents of second array which are greater then 50 into another array and display it. till now i have successfully copied an array contents into another.

i am having problem in getting the contents which are greater then 50. any how i used JG for that.but when i jump it does not goes back from where it actually jumped.

here is my code what i have done so far.

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
mymsg BYTE "Elements of array2 are :",0dh,0ah,0
mymsg2 BYTE "Moving elements greater than 50 in other array :",0dh,0ah,0
array1 DWORD 1, 3, 5,7,11,12,14,15,19,72,45,43,70,89,100
array2 DWORD 15 dup(?)
array3 Dword ?
.code
main proc




Mov esi, Offset array1
mov edi,offset array2
mov ecx,15
L2:
mov eax,[esi]
add esi,4
mov [edi],eax
add edi,4

loop L2



mov edi,offset array2
mov  edx,offset myMsg
    call WriteString
mov ecx,15

L3:
Mov eax,[edi]   
call writedec           
Add edi,4
call crlf

loop L3

mov  edx,offset myMsg2
     call WriteString

mov esi,offset array2

mov ecx,15
L4:
mov eax,[esi]
add esi,4
cmp eax,50
JG lable1
loop L4

lable1:
mov edi,offset array3
mov [edi],eax
add esi,4
call writedec
call crlf






    exit
main ENDP

END main`
Était-ce utile?

La solution

L4:
  x=*second_ptr;
  second_ptr++;
  if(x>=50) goto label1;
  if(--ecx) goto L4;
label1:
  *third_ptr=x;
  print(x);
  goto L4;

I think you need to branch back to the top of your loop after you copy and print the third thing. I think you have other problems with the code, but with respect to your specific question, you have to have that "loop L4" everywhere the code execution path needs to go back to the top of the loop. That or branch back to the the end of the loop or turn this into a call rather than a JG.

L4:
  x=*second_ptr;
  second_ptr++;
  if(x>=50) goto label1; 
less_than:
  if(--ecx) goto L4;
  goto jump_over
label1:
  *third_ptr=x;
  print(x);
  goto less_than;
jump_over:
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top