עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

צריך עזרה באסמבלי של מעבד MIPS, חישוב ASCII מstring

Featured Replies

פורסם

אני מנסה כבר דיי הרבה זמן רק לקרוא תווים ולהדפיס בלולאה string שנקלט מהמשתמש,

שקול ל:

while (*str)
{
cout<<str[i];
i++;
}

ואני לא ממש מצליח, הנה הקוד שכתבתי, אם מישהו מכיר את האסבלי הזה, יעזור לי מאוד...

###########################################################
# Ascii
#
###########################################################

.text
.globl main

main: li $v0, 4 #print question
la $a0, qst
syscall

li $v0, 8 #read string
la $a0, theString
li $a1, 64
syscall

li $v0, 4 #print string
syscall

add $t0, $zero, $zero #reset the counter
la $t1, theString
add $s0, $a1, $zero #ending address

loop: lbu $a0, 0($t1)
syscall
addi $t1, $t1, 1
addi $t0, $t0, 1
blt $t0, $s0, loop

li $v0, 10
syscall

.data
theString:
.space 64
line: .asciiz "\n"
qst: .asciiz "Enter String: "
age: .asciiz "Ener Age: "

בנוסף כפי שצויין בכותרת אני צריך לחשב את הערך האסקי של המילה (חיבור הערכים של התווים באסקי), אבל פרה פרה...

פורסם
  • מחבר

טוב, אחרי עוד כמה ניסינות הצלחתי, מסתבר שהייתי קרוב לפתרון, רק הקטע של ההדפסה לא היה במקום...

השאלה המקורית הייתה:

תרגיל 1

התכנית מבקשת את שם הסטודנט

ASCIIמחשבת את הסכום ב

של האותיות ומדפיסה

בנוסך התכנית שואלת את גיל הסטדנט ומדפיסה הגיל שבו צפוי לסיים הלימודים

והפתרון שלי:

###########################################################
# Ascii
# calcs the sum of the string in Ascii
###########################################################

.text
.globl main

main: li $v0, 4
la $a0, line
syscall

la $a0, qst #print question
syscall

li $v0, 8 #read string
la $a0, theString
li $a1, 64
syscall

add $t0, $zero, $zero #reset the counter
la $t1, theString
add $t3, $zero, $zero

loop: lbu $t2, 0($t1) #t3 saves the Ascii sum
add $t3, $t3, $t2
addi $t1, $t1, 1
addi $t0, $t0, 1
blt $t0, $a1, loop

li $v0, 4
la $a0, ans
syscall

addi $t3, $t3, -10
add $a0, $t3, $zero

li $v0, 1
syscall

li $v0, 4 #down line
la $a0, line
syscall

###########################################
# part II
# Reading int Age and adding 3 for "end of studies"
###########################################

li $v0, 4 #print Age question
la $a0, AGE
syscall

li $v0, 5 #read age
syscall

add $t0, $zero, $zero
addi $t0, $v0, 3

li $v0, 4
la $a0, AnsA
syscall

move $a0, $t0
li $v0, 1
syscall


li $v0, 10
syscall

.data
theString:
.space 64
line: .asciiz "\n"
qst: .asciiz "Enter String: "
ans: .asciiz "The ascii Sum is: "
AGE:.asciiz "Ener Age: "
AnsA: .asciiz "You about to finish in: the age of "

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.