# Converting Integer From -100 to 100 To Text X86 Assembly Language Assignment Solution

June 29, 2024
Rehana Magnus
Assembly Language
Rehana Magnus, PhD in Computer Science from the esteemed Acadia Institute of Technology, Canada. With 6 years of experience, specializes in assembly language programming. Proficient in low-level coding, optimizing performance, and enhancing system functionality.
Key Topics
• Instructions
Tip of the day
News

## Instructions

Objective

Write an x86 assembly language assignment that converts an integer from -100 to 100 to text.

Screenshots of output

Source Code

`format PE consoleentry _startinclude 'win32ax.inc'Number DD 0Quotient DD 0Remainder DD 0section '.text' code readable executable_start:    push ebp    mov ebp, esp    cinvoke printf, "This x86 assembly program converts an integer to text.%c%c%c%c", 10, 13, 10, 13readLoop:    cinvoke printf, "Enter an integer from -100 to 100: "    cinvoke scanf, "%d", Number ; read the integer    call [getchar] ; read enter from scanf    cinvoke printf, "%c%c", 10, 13 ; jump to next line    cmp DWORD[Number], -100 ; check if number is in range    jl endProgram ; if not, end program    cmp DWORD[Number], 100 ; check if number is in range    jg endProgram ; if not, end programtranslate:    cmp DWORD[Number], 0 ; check if it's a negative number    jge positive ; if not, print positive    cinvoke printf, "negative " ; else, print number is negative    neg DWORD[Number] ; convert number to positivepositive:    mov eax, [Number] ; load number in eax    cmp eax, 100 ; if 100    jne get2digits ; if not, print 2 digits    cinvoke printf, "one hundred" ; else, print hundred    jmp endingget2digits:    mov ebx, 10 ; load 10 to make division    mov edx, 0 ; clear edx before division    idiv ebx ; divide number by 10    mov [Quotient], eax ; save quotient    mov [Remainder], edx ; save remainder    cmp DwORD[Quotient], 0 ; if quotient 0    je Single    cmp DwORD[Quotient], 1 ; if quotient 1    je Tens    cmp DwORD[Quotient], 1 ; if quotient 1    je Tens    cmp DwORD[Quotient], 2 ; if quotient 2    je Twenty    cmp DwORD[Quotient], 3 ; if quotient 3    je Thirty    cmp DwORD[Quotient], 4 ; if quotient 4    je Forty    cmp DwORD[Quotient], 5 ; if quotient 5    je Fifty    cmp DwORD[Quotient], 6 ; if quotient 6    je Sixty    cmp DwORD[Quotient], 7 ; if quotient 7    je Seventy    cmp DwORD[Quotient], 8 ; if quotient 8    je Eighty    cmp DwORD[Quotient], 9 ; if quotient 9    je NinetyTwenty:    cinvoke printf, "twenty"    jmp OnesDigitThirty:    cinvoke printf, "thirty"    jmp OnesDigitForty:    cinvoke printf, "forty"    jmp OnesDigitFifty:    cinvoke printf, "fifty"    jmp OnesDigitSixty:    cinvoke printf, "sixty"    jmp OnesDigitSeventy:    cinvoke printf, "seventy"    jmp OnesDigitEighty:    cinvoke printf, "eighty"    jmp OnesDigitNinety:    cinvoke printf, "ninety"OnesDigit:    cmp DwORD[Remainder], 0 ; if remainder 0 in 2 digit numbers    je ending ; don't print more    cinvoke printf, "-" ; else, print dashSingle:    cmp DwORD[Remainder], 0 ; if remainder 0    je Zero    cmp DwORD[Remainder], 1 ; if remainder 1    je One    cmp DwORD[Remainder], 2 ; if remainder 2    je Two    cmp DwORD[Remainder], 3 ; if remainder 3    je Three    cmp DwORD[Remainder], 4 ; if remainder 4    je Four    cmp DwORD[Remainder], 5 ; if remainder 5    je Five    cmp DwORD[Remainder], 6 ; if remainder 6    je Six    cmp DwORD[Remainder], 7 ; if remainder 7    je Seven    cmp DwORD[Remainder], 8 ; if remainder 8    je Eight    cmp DwORD[Remainder], 9 ; if remainder 9    je NineZero:    cinvoke printf, "zero"    jmp endingOne:    cinvoke printf, "one"    jmp endingTwo:    cinvoke printf, "two"    jmp endingThree:    cinvoke printf, "three"    jmp endingFour:    cinvoke printf, "four"    jmp endingFive:    cinvoke printf, "five"    jmp endingSix:    cinvoke printf, "six"    jmp endingSeven:    cinvoke printf, "seven"    jmp endingEight:    cinvoke printf, "eight"    jmp endingNine:    cinvoke printf, "nine"    jmp endingTens:    cmp DwORD[Remainder], 0 ; if remainder 0    je Ten    cmp DwORD[Remainder], 1 ; if remainder 1    je Eleven    cmp DwORD[Remainder], 2 ; if remainder 2    je Twelve    cmp DwORD[Remainder], 3 ; if remainder 3    je Thirteen    cmp DwORD[Remainder], 4 ; if remainder 4    je Fourteen    cmp DwORD[Remainder], 5 ; if remainder 5    je Fifteen    cmp DwORD[Remainder], 6 ; if remainder 6    je Sixteen    cmp DwORD[Remainder], 7 ; if remainder 7    je Seventeen    cmp DwORD[Remainder], 8 ; if remainder 8    je Eighteen    cmp DwORD[Remainder], 9 ; if remainder 9    je NineteenTen:    cinvoke printf, "ten"    jmp endingEleven:    cinvoke printf, "eleven"    jmp endingTwelve:    cinvoke printf, "twelve"    jmp endingThirteen:    cinvoke printf, "thirteen"    jmp endingFourteen:    cinvoke printf, "fourteen"    jmp endingFifteen:    cinvoke printf, "fifteen"    jmp endingSixteen:    cinvoke printf, "sixteen"    jmp endingSeventeen:    cinvoke printf, "seventeen"    jmp endingEighteen:    cinvoke printf, "eighteen"    jmp endingNineteen:    cinvoke printf, "nineteen"ending:    cinvoke printf, "%c%c%c%c", 10, 13, 10, 13 ; leave empty line    jmp readLoop ; read another numberendProgram:    call [getchar] ; wait until user presses a key    mov esp, ebp    pop ebp    call [ExitProcess] ; exit the program; Import sectionsection '.idata' import data readablelibrary kernel32, 'kernel32.dll', \        msvcrt,'msvcrt.dll'import kernel32, \import msvcrt, \        printf, 'printf', scanf, 'scanf', \        getchar, 'getchar'`

## Related Samples

Dive into our Assembly Language Assignments samples for comprehensive solutions crafted to aid students. Navigate intricate concepts from basic instructions to complex system calls with clarity. Explore concise, annotated code snippets that unravel the nuances of Assembly Language, empowering students to master low-level programming effortlessly.