اذهب إلى المحتوى
  • 0

برنامج تحويل من العد الثماني إلى العد العشري بلغة التجميع assembly

RAA

السؤال

Recommended Posts

  • 0

بالنظر إلى الرقم الثماني كمدخل ، نحتاج إلى كتابة برنامج لتحويل الرقم الثماني المحدد إلى رقم عشري مكافئ.

  • قم بتحميل القيمة المخزنة في السجل
  • قسّم القيمة على 10
  • ادفع الباقي في المكدس
  • زيادة العد
  • كرر الخطوات حتى تصبح قيمة السجل أكبر من 0
  • حتى العد أكبر من الصفر
  • قم بتفريغ المكدس
  • أضف 48 إلى العنصر العلوي لتحويله إلى ASCII
  • اطبع الحرف باستخدام المقاطعة
  • إنقاص العدد
.model small
.stack
.data
    CR equ 13
    lf equ 10
    Introduction db cr,lf,09H,">هذا البرنامج يحول عشري إلى ثماني عشري<$"
    Students db cr,lf,09H,"    >TEST<$"
    Lab db cr,lf,09H,09H,09H,">TEST<$"
    Section db cr,lf,09h,09h,09h,09h,">TEST<$"
    Oct db cr,lf,0Ah,09H,">Octal Decimal<$"
    Hexa db cr,lf,0Ah,09H,">Hexadecimal<$"
    message1 db cr,lf,09H,"أدخل رقمًا عشريًا في نطاق 0-65535: $"
    message3 db cr,lf,0Ah,09H,09H, "الرقم الثماني المكافئ هو:$"
    message4 db cr,lf,0Ah,09H,09H, "الرقم السداسي العشري المكافئ هو:$"
    Again db cr,lf,0Ah,09h,"هل تريد المحاولة مرة أخرى؟ (نعم / لا)$"
    Bye db cr,lf,0Ah,09H,09H,09H," >شكرا لك و الى اللقاء!<$"

Buffer          dw 6
                dw 0
                    dw 6 dup(0)

Multiplier      dw 0ah

.code
org 100h

start:
    mov cx,0000h
    mov dx,184fh
    mov bh,21h
    mov ah,6
    int 10h

    mov dh,0
    mov dl,0
    mov bh,0
    mov ah,2
    int 10h

    mov ax,@data
    mov ds, ax

    lea dx,Introduction
    mov ah,9
    int 21h

    lea dx,Students
    mov ah,9
    int 21h

    lea dx,Lab
    mov ah,9
    int 21h

    lea dx,Section
    mov ah,9
    int 21h
    jmp Octal   
try:        
lea dx,Again
mov ah,9
int 21h

xor ah,ah
int 16h
mov bl,al

mov dl,al
mov ah,02h
int 21h

cmp bl,'Y'
je start
cmp bl,'y'
je start
cmp bl,'N'
je stop
cmp bl,'n'
je stop
stop :
lea dx,Bye
mov ah,9
int 21h

mov ax,4C00h 
int 21h 
Octal:

lea dx,Oct
mov ah,9
int 21h

mov dx,offset message1
mov ah,09h
int 21h

mov ah, 0ah
lea dx, Buffer
int 21h

mov si, offset Buffer + 2
mov cl, byte ptr [si-1]
mov ch, 00h
OctSubtract :
mov al, byte ptr [si]
cmp al, 30h
jnb OctCont1
jmp stop
OctCont1 :
cmp al, 3ah
jb OctCont2
jmp stop

OctCont2 :
sub al, 30h
mov byte ptr [si], al
inc si
loop OctSubtract
mov si, offset Buffer + 2
mov cl, byte ptr [si-1]
mov ch, 00h
mov ax, 0000h
OctCalc :
mul Multiplier
mov bl, byte ptr [si]
mov bh, 00h
add ax, bx
inc si
loop OctCalc
mov si, offset Buffer + 2
mov bx, ax
mov dx, 0000h
mov ax, 8000h
OctOctConvert :
mov cx, 0000h
OctConv :
cmp bx, ax
jb OctCont3
sub bx, ax
inc cx
jmp OctConv
OctCont3 :
add cl, 30h
mov byte ptr [si], cl
inc si
mov cx, 0008h
div cx
cmp ax, 0000h
jnz OctOctConvert
mov byte ptr [si], '$'

lea dx,message3
mov ah,9
int 21h
mov dx, offset Buffer + 2
int 21h

Hex:
    mov si, offset Buffer + 2
    mov cl, byte ptr [si-1]
    mov ch, 00h
 hexsubtract :
    mov al, byte ptr [si]
    cmp al, 30h
    jnb hexcont1

    jmp stop
 hexcont1 :
    cmp al, 3ah
    jb hexcont2

    jmp stop
 hexcont2 :
    sub al, 30h
    mov byte ptr [si], al

    inc si
    loop hexsubtract

    mov si, offset Buffer + 2
    mov cl, byte ptr [si-1]
    mov ch, 00h
    mov ax, 0000h
 hexcalc :
    mul Multiplier
    mov bl, byte ptr [si]
    mov bh, 00h
    add ax, bx
    inc si
    loop hexcalc

    mov si, offset Buffer + 2
    mov bx, ax
    mov dx, 0000h
    mov ax, 1000h
hexconvert :
    mov cx, 0000h
conv :
    cmp bx, ax
    jb hexcont3
    sub bx, ax
    inc cx
    jmp conv
hexcont3 :
    cmp cx, 0ah
    jb hexcont4
    add cl, 37h
    jmp hexcont5
hexcont4 :
    add cl, 30h
hexcont5 :
    mov byte ptr [si], cl
    inc si
    mov cx, 0010h
    div cx
    cmp ax, 0000h
    jnz hexconvert

    mov byte ptr [si], '$'
    lea dx,message4
    mov ah,9
    int 21h
    lea dx,Buffer + 2
    int 21h
    jmp Try

end start

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ On 30‏/10‏/2022 at 23:36 قال Ahmed Sadek:

بالنظر إلى الرقم الثماني كمدخل ، نحتاج إلى كتابة برنامج لتحويل الرقم الثماني المحدد إلى رقم عشري مكافئ.

  • قم بتحميل القيمة المخزنة في السجل
  • قسّم القيمة على 10
  • ادفع الباقي في المكدس
  • زيادة العد
  • كرر الخطوات حتى تصبح قيمة السجل أكبر من 0
  • حتى العد أكبر من الصفر
  • قم بتفريغ المكدس
  • أضف 48 إلى العنصر العلوي لتحويله إلى ASCII
  • اطبع الحرف باستخدام المقاطعة
  • إنقاص العدد

.model small
.stack
.data
    CR equ 13
    lf equ 10
    Introduction db cr,lf,09H,">هذا البرنامج يحول عشري إلى ثماني عشري<$"
    Students db cr,lf,09H,"    >TEST<$"
    Lab db cr,lf,09H,09H,09H,">TEST<$"
    Section db cr,lf,09h,09h,09h,09h,">TEST<$"
    Oct db cr,lf,0Ah,09H,">Octal Decimal<$"
    Hexa db cr,lf,0Ah,09H,">Hexadecimal<$"
    message1 db cr,lf,09H,"أدخل رقمًا عشريًا في نطاق 0-65535: $"
    message3 db cr,lf,0Ah,09H,09H, "الرقم الثماني المكافئ هو:$"
    message4 db cr,lf,0Ah,09H,09H, "الرقم السداسي العشري المكافئ هو:$"
    Again db cr,lf,0Ah,09h,"هل تريد المحاولة مرة أخرى؟ (نعم / لا)$"
    Bye db cr,lf,0Ah,09H,09H,09H," >شكرا لك و الى اللقاء!<$"

Buffer          dw 6
                dw 0
                    dw 6 dup(0)

Multiplier      dw 0ah

.code
org 100h

start:
    mov cx,0000h
    mov dx,184fh
    mov bh,21h
    mov ah,6
    int 10h

    mov dh,0
    mov dl,0
    mov bh,0
    mov ah,2
    int 10h

    mov ax,@data
    mov ds, ax

    lea dx,Introduction
    mov ah,9
    int 21h

    lea dx,Students
    mov ah,9
    int 21h

    lea dx,Lab
    mov ah,9
    int 21h

    lea dx,Section
    mov ah,9
    int 21h
    jmp Octal   
try:        
lea dx,Again
mov ah,9
int 21h

xor ah,ah
int 16h
mov bl,al

mov dl,al
mov ah,02h
int 21h

cmp bl,'Y'
je start
cmp bl,'y'
je start
cmp bl,'N'
je stop
cmp bl,'n'
je stop
stop :
lea dx,Bye
mov ah,9
int 21h

mov ax,4C00h 
int 21h 
Octal:

lea dx,Oct
mov ah,9
int 21h

mov dx,offset message1
mov ah,09h
int 21h

mov ah, 0ah
lea dx, Buffer
int 21h

mov si, offset Buffer + 2
mov cl, byte ptr [si-1]
mov ch, 00h
OctSubtract :
mov al, byte ptr [si]
cmp al, 30h
jnb OctCont1
jmp stop
OctCont1 :
cmp al, 3ah
jb OctCont2
jmp stop

OctCont2 :
sub al, 30h
mov byte ptr [si], al
inc si
loop OctSubtract
mov si, offset Buffer + 2
mov cl, byte ptr [si-1]
mov ch, 00h
mov ax, 0000h
OctCalc :
mul Multiplier
mov bl, byte ptr [si]
mov bh, 00h
add ax, bx
inc si
loop OctCalc
mov si, offset Buffer + 2
mov bx, ax
mov dx, 0000h
mov ax, 8000h
OctOctConvert :
mov cx, 0000h
OctConv :
cmp bx, ax
jb OctCont3
sub bx, ax
inc cx
jmp OctConv
OctCont3 :
add cl, 30h
mov byte ptr [si], cl
inc si
mov cx, 0008h
div cx
cmp ax, 0000h
jnz OctOctConvert
mov byte ptr [si], '$'

lea dx,message3
mov ah,9
int 21h
mov dx, offset Buffer + 2
int 21h

Hex:
    mov si, offset Buffer + 2
    mov cl, byte ptr [si-1]
    mov ch, 00h
 hexsubtract :
    mov al, byte ptr [si]
    cmp al, 30h
    jnb hexcont1

    jmp stop
 hexcont1 :
    cmp al, 3ah
    jb hexcont2

    jmp stop
 hexcont2 :
    sub al, 30h
    mov byte ptr [si], al

    inc si
    loop hexsubtract

    mov si, offset Buffer + 2
    mov cl, byte ptr [si-1]
    mov ch, 00h
    mov ax, 0000h
 hexcalc :
    mul Multiplier
    mov bl, byte ptr [si]
    mov bh, 00h
    add ax, bx
    inc si
    loop hexcalc

    mov si, offset Buffer + 2
    mov bx, ax
    mov dx, 0000h
    mov ax, 1000h
hexconvert :
    mov cx, 0000h
conv :
    cmp bx, ax
    jb hexcont3
    sub bx, ax
    inc cx
    jmp conv
hexcont3 :
    cmp cx, 0ah
    jb hexcont4
    add cl, 37h
    jmp hexcont5
hexcont4 :
    add cl, 30h
hexcont5 :
    mov byte ptr [si], cl
    inc si
    mov cx, 0010h
    div cx
    cmp ax, 0000h
    jnz hexconvert

    mov byte ptr [si], '$'
    lea dx,message4
    mov ah,9
    int 21h
    lea dx,Buffer + 2
    int 21h
    jmp Try

end start

 

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
  
   
   int ConvertOctaltoDecimal ( int octal ) {
        int decimal = 0 , position =0 ;
        while ( octal > 0 ) {
            if(position < 3){
             int temp = octal % 10 ;
             decimal = decimal + temp * pow( 8 , position );
             octal = octal / 10;
            position = position + 1 ;
        }
        else {
            cout << "error, more then three digits";
            return 0;
        }
        }
         return decimal ;
     }
     
     
    int CheckOctal ( int octal ) {
      
        while ( octal > 0 ) {
          int temp = octal % 10 ;
         
          if ( temp == 8 || temp ==9) {
               return 0 ;
             }
             octal = octal / 10 ;
        }
        return 1;
   }
   
   
  
   int main() {
       for (int i = 0; i < 3 ; i++){
        cout << "\nPlease Enter octal number from three digits: \n";
        int octal;
        cin >> octal;
    
     int check = 0 ;
     check = CheckOctal ( octal );
      if( check == 0){
           cout << "\nInvalid Input\n" ;
      }
      else {
          int decimal = 0;
          decimal = ConvertOctaltoDecimal ( octal ) ;
          if (decimal != 0){
         cout << "This is decimal " << decimal << endl ; 
          }
   }}
        return 0 ;
   }

انا عملتو الكود بلغة سي بلس لكن بواجه صعوبة في تحويلو الى الاسمبلي ؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...