נושאים פעיליםנושאים פעילים  הצגת רשימה של חברי הפורוםרשימת משתמשים  חיפוש בפורוםחיפוש  עזרהעזרה
  הרשמההרשמה  התחברותהתחברות RSS עדכונים
תיכנות
RSS UnderWarrior Forums : RSS תיכנות
נושא

נושא: עזרה באסמבלר(את"מ)

שליחת תגובהשליחת נושא חדש
כותב
הודעה << נושא קודם | נושא הבא >>
lirany
משתמש מתחיל
משתמש מתחיל


הצטרף / הצטרפה: 15 March 2005
משתמש: מנותק/ת
הודעות: 49
נשלח בתאריך: 28 April 2005 בשעה 19:07 | IP רשוּם
ציטוט lirany

 
הנה התרגיל:

מטלה 5

 

קלט ממקלדת, שני מספרים  דו ספרתים ,  בצע בינהם כפל, ללא פעולת כפל ( הזזות חיבורים ללא לולאה). את התוצאה הכנס לאוגרר bx

חזור על הפעולה  עם פקודת mul  , ). את התוצאה הכנס לאוגר ax  והשווה תוצאות.

 

רמז: כפל בסכום/הפרש  חזקות של 2 שמרכיבות את המספר. לדוגמא : n*15 = n*(16-1)

או : n*(64+32+4) == n*100

 

בשלב זה אין להציג תוצאה למסך, אלא משפט מסקנה, "הגעתי לתוצאות שוות/ שונות"

 

 אני הבנתי אותו בצורה כזאת יש לפנינו שתי שיטות לכפול באסמבלר
אחת על ידי הזזות וכו
 והשניה עם פעולת
mul
בתרגיל רוצים שנעשה עם מספרים לא מסומנים
unsigen
את התוצאה הכפל בלי פעולת מול לשים באוגר
BX
ואת תוצאת הכפל עם פעולת מול לשים באוגר
AX
ולהשוות את התוצאות
ואז לתת משפטי מסקנה"הגעתי לתוצאות שוות שונות...."
לדעתי זה מגוכך כי אם עשיתי בשתי השיטות אותה פעולה והיא נעשת בצורה טובה ותקינה למה שיהיו תוצאות שונות???
בכל אופן עשיתי את התרגיל אך משום מה הוא לא ממש עובד
את האמת הוא יותר עובד..
אני מאמין שיש טעות קטנה או שתיים
אז הנה הקוד:
ומי שיכול לעזור אז זה יהיה נפלא
 
קוד:
.model small
.stack 64
.DATA
number1 db       20 dup(55h)
number2 db 20 dup (55h)
result_with_mul   db      20 dup (55h)
result_without_mul  db 20 dup (55h)
msg1  db    'pls enter the first number with 2 digits: $ ',0ah,0dh
msg2  db     0ah,0dh,'pls enter the second number with 2 digits: $ ',0ah,0dh
msg3 db      'conclusion: results with and without mul are equal $'
msg4 db      ' conclusion: results with and without mul are not equal $'
;msg5 db  'error you have enter not what u need to pls try again $'  
        
      
 
      
 

 .CODE
      
 
 begin  proc   far
 mov     ax,@data
 mov     ds,ax
 mov     es,ax
 
        lea     di,number1
        push    di
 lea di,number2
        lea     dx,msg1
        push dx
 call disp_msg
        call get_2_digits
        lea dx,msg2
        push dx
        call disp_msg
        call get_2_digits
        call with_mul
        call without_mul
cmp al,dl
        je msg_equal
        jne msg_not_equal
msg_equal: lea cx,msg3
 push cx
         &nbs p;          &n bsp;     call disp_msg
msg_not_equal: lea cx,msg4
 push cx
 call disp_msg
  mov     ax,4c00h
 int     21h
begin   endp
;-------------------------------------
 
disp_msg proc
push bp
 mov bp,sp
 push dx
 mov dx,[bp+4]
 call    print
 pop dx
 pop bp
 ret 2
 
        disp_msg endp
;------------------------------------------
print proc 
    
        mov     ah,09h
        int     21h
 ret
 
 print endp
;--------------------------------------------
get_1_digit    proc    near
     again:       call   get_char
      cmp    al,'0'      ; check if digit
     jl     again
 
  
 

       cmp    al,'9'      ;filter 4 digits
   jg     again
     sub    al,30h      ;de-ascii
       ret
     get_1_digit    endp
;---------------------------------------------
get_2_digits    proc    near
             ;convert 2 ascii digits into number -->bl
      push   ax
     call   get_1_digit
    shl    al,1    ;*2
    mov    bl,al    ;save
     shl    al,1    ;*4
       shl    al,1      ;*8
     add    bl,al      ;10
  call   get_1_digit
     add    bl,al
       pop    ax
       ret
    get_2_digits    endp
;------------------------
get_char proc
         ;
         mov     ah,1
         int     21h
         ret
get_char  endp  
;------------------------
;_____________________________
 
with_mul  proc
 
         push    bp
         mov & nbsp;   bp,      sp          &n bsp;                    ;Another stack pointer besides sp
         push     dx   ;Saving the current values of the registers
         push    si
         xor & nbsp;     bx,    bx  ;Prepering place for the result
 
         mov & nbsp;   si,      [bp+4]  ;Reading data from the stack
         mov & nbsp;   al,      [si]  ;The value of the multiplicant
         inc        si
         mov & nbsp;   dh,     al  ;Copy of the multiplicant
         mov & nbsp;   ah,     [si]  ;The value of the multiplier
         mov & nbsp;   dl,     -1  ;In dl  the place of each bit is been saved
         mov & nbsp;   cx,     8  ;The length of one byte
 
next_bit:
         shr & nbsp;      al,   &n bsp;  1     ;Saving the place of each bit in order to know the "weight" of it
         inc & nbsp;      dl   ;Pl ace 0 =  weight 1, place 1 = weight 2, place 2 = weight 4 etc
         jc &n bsp;       &nbs   p; multi  ;If the carry fleg is '1' binary we have to add the bit's weight to the result
 
loop  next_bit
 
         jmp & nbsp;   skip   ;Reaching to this line only when the loop ends
 
multi:    ;Result=(weight*multiplier)+re sult
 
         push      ax;   Saving the current value of ax
         mov & nbsp;    al,     ah  ;Duplicate of the multiplier
         xor       ah,     ah
         push      cx   ;Saving the counter of the external loop
 
         mov      cl,     dl
         shl & nbsp;       ax,  &n bsp; cl  ;Temporary result =(weight*multiplier)!!!
         add & nbsp;        bx,   ax   ;In the end of the loop the result will be saved in bx
         pop       cx
         pop       ax
 
loop next_bit
 
skip:    ;This part calculate the result by using the mul function
         mov & nbsp;   al,      dh  ;dh=the value of the multiplier
         mul & nbsp;    ah   ;The multiplier is already exist at al (result=al*ah=ax)!!!
 
         pop        si
         pop & nbsp;      dx   ;Cl eaning the stack
         pop        bp
         ret
with_mul  endp
 
;----------------------------------
 
without_mul proc    ;Building the tens digit by multiplying – (origin digit)*10
 
        mov  & nbsp;  bl,     al  ;duplicating the origin digit
        shl  & nbsp;     bl,    &n bsp; 1  ;(The origin digit)*2
        push     cx   ;saving the current value of the external loop
 mov     cl,      3
 shl        al,     cl  ;(The origin digit)*8
        add  & nbsp;   bl,     al  ;The result saved in bl
        pop     cx
        ret
without_mul  endp
;-----------------------------------
 

end
 
חזרה לתחילת העמוד הצג את כרטיס החבר של lirany חפש הודעות אחרות של lirany
 
ניר
מנהל האתר
מנהל האתר
סמל אישי

הצטרף / הצטרפה: 12 January 2005
מדינה: Israel
משתמש: מנותק/ת
הודעות: 3296
נשלח בתאריך: 29 April 2005 בשעה 02:09 | IP רשוּם
ציטוט ניר

תוכל להביא את הקטע הראשון לא הפוך כדי שנוכל להבין מה השאלה?
חזרה לתחילת העמוד הצג את כרטיס החבר של ניר חפש הודעות אחרות של ניר בקר בדף הבית של ניר
 
ניר
מנהל האתר
מנהל האתר
סמל אישי

הצטרף / הצטרפה: 12 January 2005
מדינה: Israel
משתמש: מנותק/ת
הודעות: 3296
נשלח בתאריך: 29 April 2005 בשעה 13:08 | IP רשוּם
ציטוט ניר

ציטוט:
לדעתי זה מגוכך כי אם עשיתי בשתי השיטות אותה פעולה והיא נעשת בצורה טובה ותקינה למה שיהיו תוצאות שונות???

כל הרעיון שלהם הוא שתבדוק את עצמך

ציטוט:
בכל אופן עשיתי את התרגיל אך משום מה הוא לא ממש עובד
את האמת הוא יותר עובד..

עובד? לא עובד? מה בדיוק הבעיה? תוכל לכוון למשהו ספציפי במקום להראות את כל הקוד?
חזרה לתחילת העמוד הצג את כרטיס החבר של ניר חפש הודעות אחרות של ניר בקר בדף הבית של ניר
 
lirany
משתמש מתחיל
משתמש מתחיל


הצטרף / הצטרפה: 15 March 2005
משתמש: מנותק/ת
הודעות: 49
נשלח בתאריך: 29 April 2005 בשעה 16:04 | IP רשוּם
ציטוט lirany

כן בחלק שמחשב בלי mul

נראה לי שהתבלבלתי קצת

חזרה לתחילת העמוד הצג את כרטיס החבר של lirany חפש הודעות אחרות של lirany
 

אם ברצונך להגיב לנושא זה עליך קודם להתחבר
אם אינך רשום/ה כבר עליך להרשם

  שליחת תגובהשליחת נושא חדש
גרסת הדפסה גרסת הדפסה

קפיצה לפורום
אינך יכול/ה לשלוח נושאים חדשים בפורום זה
אינך יכול/ה להגיב לנושאים בפורום זה
אינך יכול/ה למחוק את הודעותיך ותגוביך בפורום זה
אינך יכול/ה לערוך את הודעותיך ותגובותיך בפורום זה
אינך יכול/ה לצור סקרים בפורום זה
אינך יכול/ה להצביע בסקרים בפורום זה