ברוכים הבאים לאתר תחרויות קודגורו! › פורומים › חידות › השאלה הפתוחה מתחרות שלב ב
- This topic has 12 תגובות, 7 משתתפים, and was last updated לפני 23 שנים, 4 חודשים by
old_t.
-
מאתתגובות
-
24 בספטמבר 2001 בשעה 12:11 #77275
CodeGuru
מנהל בפורוםכתוב קטע קוד בשפת אסמבלי קצר ככל האפשר שפעולתו זהה לקטע הבא
PUSHF
ADD BX,CX
SUB CX,BX
ADD BX,CX
XOR CX,FFFF
INC CX
POPF24 בספטמבר 2001 בשעה 16:20 #78852Alon
משתתףכותרת: my answer
strange , when i did the test i thougth it does cx=-bx , i dont know why i thought so . when i checked it again(today ) i was notice that its just exchange between cx and bx (wired – probably there is a trick. when there is overflow or something )
but if there is not trick
just do XCHG cx,bx (takes 3 clocks . doesnt change the flags) so you dont need to push and pop.)Bye
Alon25 בספטמבר 2001 בשעה 23:19 #78853eToken
משתתףכותרת: בדיוק, אבל בדיוק ממש מה שקרה לי!!
27 בספטמבר 2001 בשעה 23:13 #78857כותרת: התשובה שלי
add bx, cx ; bx´ := bx + cx
sub cx, bx ; cx´ := cx – bx´ => cx := cx – bx -cx = (-bx)
add bx, cx ; bx´ := bx´ + cx´ => bx´ := bx + cx + (-bx) = cx
xor cx 0FFFF
inc cx ; These two last instructions as far as I remember make (-bx)
; into (bx)so, it can be written :
mov ax, cx
mov cx, bx
mov bx, axCan be as well written without ax, but it will still take 3 instructions.
29 בספטמבר 2001 בשעה 19:47 #78861דניאל ק
משתתףכותרת: כן
29 בספטמבר 2001 בשעה 19:47 #78862דניאל ק
משתתףכותרת: זה באמת מחליף
29 בספטמבר 2001 בשעה 19:47 #78863דניאל ק
משתתףכותרת: זה באמת מחליף
29 בספטמבר 2001 בשעה 19:50 #78864דניאל ק
משתתףכותרת: זה באמת מחליף, אבל אתה שוכח דבר אחד:
בקוד שלך אתה משתמש באוגר נוסף, כך שהקוד אינו זהה.
אני נקטתי בשיטה שונה(אבל לא הנכונה ביותר שהיא XCHG)
PUSH BX
PUSH CX
POP BX
POP CXעל ידי שימוש במחסנית הכנסתי את ערכי BX וCX ואז שלפתי אותם בסדר הפוך.
29 בספטמבר 2001 בשעה 19:50 #78865דניאל ק
משתתףכותרת: אופס, זה לא היה אמור לקרות
30 בספטמבר 2001 בשעה 16:49 #78878Alon
משתתףכותרת: you are right but slow
hii
you answer with push and pop , nice but slower …if you compare it to xchg or to Venndigram´s answer:
the problem with Venndigram´s answer that you need another register… the problem with your answer that pop is kinda slow … , another thing . size bytes .: xchg 2 bytes
the moves answer – 3 mov , every mov 2 bytes = 6 bytes
push and pop each one of them 1 byte * 4 =4 bytes ,.bye
Alon
30 בספטמבר 2001 בשעה 17:06 #78879דניאל ק
משתתףכותרת: אני יודע ש XCHG זאת הדרך, אבל חבל שלא ידעתי את זה
בשלב התחרות. זה לא משנה כי זה לא השפיע על הציון, רק במקרה של תיקו זה היה משפיע24 באוקטובר 2001 בשעה 09:14 #78893דוד
משתתףכותרת: יש עוד דרך להחלפה מהירה:
ללא שימוש במחסנית או אוגר נוסף.
XOR CX, BX
XOR BX, CX
XOR CX, BX17 ביולי 2002 בשעה 20:12 #78945old_t
משתתףכותרת: אני אוהב את התשובה הזו
PUSHF
XOR BX,CX
XOR CX,BX
XOR BX,CX
POPF -
מאתתגובות
- יש להתחבר למערכת על מנת להגיב.