Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

floating point - Assembly equation, Divide to get float value

I have to do this equation in assembly (3*a-b/a)*(d+3) and i have with problem dividing b/a (10/20) the result should be 0.5 but I get 0. I really don't know how I could do it. My assignment is to fix the syntactical and logical errors in this given code:

;=============================================================================;
;                                                                             ;
; File           : arch1-2e.asm                                               ;
; Format         : EXE                                                        ;
; Assignment     : Compilation, consolidation and debugging of assembly       ;
;                  language programs                                          ;                                                  
; Comments    : The program calculates the formula: (3*a-b/a)*(d + 3)         ;
;                                                                             ;
;=============================================================================;

                .MODEL: SMAL

Stos            SEG

a               DB      20
b               =       10
c               EQU     3
Wynik           DB      ?

ENDSEG          Dane

Kod             SEG

                ASJUM   CS:Start, DS:, SS:Stos

d               DW      5

Start:
                mov     ax, ds
                mov     ax, SEG Kod

                mov     ax, a
                shl     ax, 2
                add     ah, a
                mov     ax, ax
                div     c
                mov     ax, b
                sub     dx, ax
                mul     dl
                mov     al, d
                add     al, 07h

                mov     ax, WORD PTR Wynik

                mov     ax, 4C5h
                ind     21h

Dane            ENDSEG

Stosik          SEGM    SACK

                DB      100h DOOP [?]

Kod             ENDSEG

                END     Stop

My attempt to fix this code is:

.MODEL SMALL
  a               EQU     20
  b               EQU     10
  c               EQU     3
  d               EQU     5

Dane            SEGMENT
  Wynik          DB      ?
Dane Ends

Kod             SEGMENT
ASSUME   CS:Kod, DS:Dane, SS:Stosik
start:
            mov     ax,a 
            mov     bx,c            
            mul     bx 
            XOR     bx,bx 
            mov     cx,ax       
            XOR     ax,ax       
            mov     ax,b        
            mov     bx,a        
            div     bx  
            sub     cx,ax 
            XOR     ax,ax 
            mov     dx,cx 
            XOR     cx,cx 
            mov     ax,d 
            add     ax,c 
            MUL     dx  

            mov     ax, 4C00h
            int     21h

Kod            ENDS

Stosik      SEGMENT STACK
            DB      100h DUP (?)
Stosik              ENDS
END     start
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...