Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:19:54+00:00 2026-06-17T07:19:54+00:00

I wrote a simple program in x86 assembly and I tried to run it

  • 0

I wrote a simple program in x86 assembly and I tried to run it using TASM(Turbo) and TLINK.

When I input 4 and 3, subtraction outputs / and not 1, as it should.

But when I input 3 and 4, I get the correct result.

Sum and sort work fine, code is not correct just for subtraction.

Any help?

code Tasm

.model small
.stack
.code

DONNEES SEGMENT

    Nombre1Msg       db 'Entrez le 1er chiffre:$'
    Nombre2Msg       db 'Entrez le 2er chiffre:$'
    DifferenceMsg    db 'Leur difference:$'
    SommeMsg         db 'Leur Somme:$'
    AscMsg           db 'En Ordre croissant:$'
    DescMsg          db 'En Order decroissant:$'
    Sperateur        db ',$'
    return           db 0DH,0AH,('$')

    Nombre1          db 
    Nombre2          db
    Somme            db
    Difference       db 

DONNEES ENDS

Main PROC FAR

ASSUME DS:DONNEES
MOV AX,DONNEES 
MOV DS,AX

MOV DX,offset Nombre1Msg
MOV AH,9
INT 21H


MOV AH,1 ; saisie
INT 21H ; le caractere lu arrive dans AL
Sub AL,'0';le chiffre= code ASCII-ASCII(0)
MOV Nombre1,AL

call LineFeed

MOV DX,offset Nombre2Msg
MOV AH,9
INT 21H

MOV AH,1 ; saisie
INT 21H ; le caractere lu arrive dans AL
Sub AL,'0';le chiffre= code ASCII-ASCII(0)
MOV Nombre2,AL

CMP Nombre1,AL ; 2éme chifre en AL
JL Permutation
Permutation:
MOV AL,Nombre1
MOV AH,Nombre2
MOV Nombre1,AH
MOV Nombre2,AL


MOV AL,Nombre1
SUB AL,Nombre2
MOV Difference,AL


MOV Al,Nombre1
add AL,Nombre2
MOV Somme,AL

call LineFeed

MOV DX,offset DifferenceMsg
MOV AH,9
INT 21H

MOV DL,Difference
ADD DL,48
MOV AH,2
INT 21H


call LineFeed

MOV DX,offset SommeMsg
MOV AH,9
INT 21H

MOV DL,Somme
ADD DL,48
MOV AH,2
INT 21H

call LineFeed

MOV DX,offset AscMsg
MOV AH,9
INT 21H

MOV DL,Nombre2
ADD DL,48
MOV AH,2
INT 21H

MOV DX,offset Sperateur
MOV AH,9
INT 21H

MOV DL,Nombre1
ADD DL,48
MOV AH,2
INT 21H

call LineFeed

MOV DX,offset DescMsg
MOV AH,9
INT 21H

MOV DL,Nombre1
ADD DL,48
MOV AH,2
INT 21H

MOV DX,offset Sperateur
MOV AH,9
INT 21H

MOV DL,Nombre2
ADD DL,48
MOV AH,2
INT 21H

MOV AH,4CH 
INT 21H
Main ENDP    

    LineFeed proc near
    MOV dx,offset return
    MOV ah,9
    int 21h
    ret
    LineFeed endp

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:19:55+00:00Added an answer on June 17, 2026 at 7:19 am

    Well, here’s one bug. Your sorting code has a conditional jump (jl in this case) that has no effect as it only jumps to the next instruction, that will be executed next anyway:

    CMP Nombre1,AL ; 2éme chifre en AL
    JL Permutation
    Permutation:
    MOV AL,Nombre1
    MOV AH,Nombre2
    MOV Nombre1,AH
    MOV Nombre2,AL
    

    Your variable names Nombre1 and Nombre2 aren’t very descriptive. If you want to have variable names in French, I’d change Nombre1 eg. to Nombre_plus_grande (or bigger_number in English) and Nombre2 eg. to Nombre_plus_grande (or smaller_number in English). Otherwise, it’s difficult to debug the code when variable names don’t mean anything.

    Fixed version with English variable names (to make it better understandable to most people):

    bigger_number db
    smaller_number db
    
    mov smaller_number,al ; store 2nd input into smaller_number
    cmp bigger_number,al  ; 1st input in bigger_number, 2nd input in al
    jae order_ready       ; if numbers are equal or if bigger_number is bigger,
                          ; there's then nothing to do.
        xchg al,bigger_number    ; exchange al (2nd input) and bigger_number
        mov smaller_number,al    ; store al (now the 1st input) into smaller_number
    order_ready:
    

    Note I also changed signed jl (jump if less) to unsigned jae (jump if above or equal; jae, jnb and jnc are synonymous). As this code doesn’t handle negative numbers, I think it’s better to be consistent with the jumps too. jge/jnl (jump if greater or equal/jump if not less) would work too. You may want to check Intel x86 JUMP quick reference.

    After this fix you should replace the variable names accordingly in other parts of the code.

    mov al,bigger_number
    sub al,smaller_number
    mov Difference,AL
    
    mov al,bigger_number
    add al,smaller_number
    mov Somme,al
    

    If the sum goes above 9, then it outputs trash. Subtraction, however, should work always correctly for valid inputs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write simple programs (console input/output) for Windows using x86 assembly,
I wrote a simple program that using Class::ArrayObjects but It did not work as
I am using Ubuntu 12.04 LTS. I wrote a simple program as follows to
I wrote a simple program in c++: #include<iostream> using namespace std; int main() {
I wrote a simple program, here's what it looks like, some details hidden: using
I wrote a simple program that accesses a file called input.txt and pushes its
I wrote a simple program to test array pointer: #include <iostream> using namespace std;
So I am working on an x86 Assembly program for Linux using NASM. This
I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B
I wrote a simple program to test a theory that finally block will always

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.