2016-02-21 67 views
-3

非常感謝您的幫助,我已經完成了所有更改,如下所示。然而,它不工作... :( 我可能做錯了什麼,你介意接受另一個選擇? 謝謝你所做的一切!procs avg和IsZugi無法在我的彙編代碼中工作

我忘了提及,我創建了幾個數組如果它使任何differens ... ArrayA DW 9 DUP(0) ArrayB DW 9 DUP(0) ArrayC DW 9 DUP(0) proc Part2 GoAgain: mov ah, 1 ;receives a number int 21h cmp al,65 ;checks if A jne TryNext call PrintA jmp GoAgain TryNext:cmp al,66 ;checks if B jne TryNext2 call PrintB jmp GoAgain TryNext2: cmp al,67 ;checks if C jne TryNext3 call PrintC jmp GoAgain TryNext3: cmp al,69 ;checks if E jne TryNext4 push offset counter call IsZugi jmp GoAgain TryNext4: cmp al,80 ;checks if P jne TryNext5 push offset counter call IsZugi jmp GoAgain TryNext5: cmp al,86 jne TryNext6 push offset counter call avg jmp GoAgain TryNext6: cmp al,'#' jne TryAgain ret TryAgain:mov dx, offset message2 mov ah, 9h int 21h jmp GoAgain ret endp Part2 proc PrintA mov dl,'a' mov ah, 2h int 21h mov bx,0 again: cmp [bx],0 ;checks if index isnt empty jne NotEnd2 ret NotEnd2:mov dl,' ' ;print space mov ah, 2h int 21h mov ax,[word ptr bx] add al,30h mov dl,al;print the number mov ah, 2h int 21h inc bx ;goes to the next index jmp again ret endp PrintA proc PrintB mov dl,'b' mov ah, 2h int 21h mov bx,10 again2: cmp [bx],0 ;checks if index isnt empty jne NotEnd2 ret NotEnd3:mov dl,' ' ;print space mov ah, 2h int 21h mov ax,[word ptr bx] add al,30h mov dl,al;print the number mov ah, 2h int 21h inc bx ;goes to the next index jmp again ret endp PrintB proc PrintC mov dl,'c' mov ah, 2h int 21h mov bx,20 again3: cmp [bx],0 ;checks if index isnt empty jne NotEnd2 ret NotEnd4:mov dl,' ' ;print space mov ah, 2h int 21h mov ax,[word ptr bx] add al,30h mov dl,al;print the number mov ah, 2h int 21h inc bx ;goes to the next index jmp again ret endp PrintC proc IsZugi pop [ReturnAddress] pop si;counter mov dx,0 mov bx,0;the beginning redo: mov ax,2;to check if number%2=0 mov dx,0 mov cx,[bx];cx=number cmp cx,0;checks if index=null je next;all the array was read mov di,ax mov ax,cx mov cx,di div cx;number/2 inc bx cmp dx,0;to check if number%2=0 jne redo;go to the next index inc [word ptr si];inc counter jmp redo next: inc dx cmp dx,2 ja LastArray mov bx,10;moves to the second array jmp redo LastArray: cmp dx,3 je done mov bx,29;moves to the last array jmp redo done: mov dl,'P';print p mov ah, 2h int 21h mov dl,' ';print space mov ah, 2h int 21h mov al,[byte ptr si] add al,30h mov dl,al;print the counter mov ah, 2h int 21h mov dl,'E';print e mov ah, 2h int 21h mov dl,' ';print space mov ah, 2h int 21h mov cl,[byte ptr si] mov ch,9 sub ch,cl add ch,30h mov dl,ch;print the 9-counter int 21h push [ReturnAddress]

  ret 
endp IsZugi 
proc IsLegal 
     mov bx,0 
     pop [ReturnAddress] 
     pop ax ;receives the number 
     cmp ax, 8 ;checks if belongs to A 
     jb B 
occupied?: 
     cmp [word ptr bx],0;occupied or not 
     je NotOccupied 
     inc bx 
     jmp occupied? 
NotOccupied: 
     mov [bx],ax ;enters the number to it's place 
     jmp finish 
B:  cmp ax,6 ;checks if belongs to B 
     jb CC 
     add bx,10 ;moves to the next array 
occupied2?: cmp [word ptr bx],0 ;checks if index occupied 
     je NotOccupied2 
     inc bx ;checks next index 
     jmp occupied2? 
NotOccupied2: mov [bx],ax ;enters the value to it's array 
     jmp finish 
CC:  add bx,20 ;the beginning of the next array 
occupied3?: cmp [word ptr bx],0 ;checks if empty 
     je NotOccupied3 
     inc bx ;checks next index 
     jmp occupied3? 
NotOccupied3: 
     mov [bx],ax ;enters the value to it's array 
finish: cmp ax,9 ;checks if legal 
     ja FalseExit  ;if illegal exit 
     cmp ax,0 ;checks if legal 
     jl FalseExit  ;if illegal exit 
     push 0  ;since we poped ax 
     push [ReturnAddress] 
     ret 
endp IsLegal 
proc avg 
     pop [ReturnAddress] 
     mov bx,0 ;first index 
     pop si  ;si=sum 
suming: mov ax,[word ptr si] ;it's impossible to do- mov [si],[bx] so... 
     add ax,[bx];sum+=bx 
     mov [word ptr si],ax 
     inc bx 
     cmp bx,29 
     jne suming 
     mov dx, offset message ;print avg 
     mov ah, 9h 
     int 21h 
     mov ax,[word ptr si] 
     mov [word ptr si],9 
     div ax 
     add al,30h 
     mov dl,al 
     mov ah,2 
     int 21h 
     push 0 
     push [ReturnAddress] 
     ret 
endp avg 
start: 
     jmp TrueStart 
FalseExit: jmp exit   
TrueStart: mov ax, @data 
     mov ds, ax 
     mov cx,9 ;loop*9 
zloop: mov ah, 1 ;receives a number 
     int 21h 
     sub al,30h ;reveal the real number 
     mov ah,0 ;we only need al, however we can only push word 
     push ax  ;pushes the number 
     call IsLegal 
     ;loop zloop 
     push offset sum 
     call avg 
     push offset counter 
     ;call IsZugi 
     ;call PrintA 
     ;call PrintB 
     ;call PrintC 
     ;call Part2 
     call Creative 

<\code>

+1

請不要像你從答案中得到的信息那樣改變問題! – Fifoernik

+0

最起碼這個答案 - __已經明顯地幫助你了!__ - 在再次問同樣的問題之前。 – Fifoernik

回答

1
proc IsZugi 
    pop [ReturnAddress] 
    pop si;counter 

Each time you call IsZugi there no mention of an extra argument. So where do get the pop si而來?
同樣的評論;counter是誤導,因爲它似乎是計數器的地址

TryNext3: cmp al,69 ;checks if E 
    jne TryNext4 
    push offset counter  <<< add this 
    call IsZugi 
    jmp GoAgain 
TryNext4: cmp al,80 ;checks if P 
    jne TryNext5 
    push offset counter  <<< add this 
    call IsZugi 
    jmp GoAgain 
TryNext5: cmp al,86 
    jne TryNext6 
    push offset counter  <<< add this 
    call avg 
    jmp GoAgain 

 mov dx,0 
     mov bx,0;the beginning 
redo: mov ax,2;to check if number%2=0 

你需要重複mov dx,0每個重做得到正確的劃分。

 mov bx,0;the beginning 
redo: mov ax,2;to check if number%2=0 
     mov dx,0 

div cx;number/2 
inc bx 
cmp ah,0;to check if number%2=0 

既然你已經做了師必須在DX寄存器來檢查任何剩餘部分,而不是在AH註冊!

+1

最起碼這個答案 - __已經明顯地幫助你了!__ - 再次問同樣的問題之前。 – Fifoernik