Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Transforms septenary number into an decimal number. MASM assembly language Conte

ID: 3717855 • Letter: T

Question

Transforms septenary number into an decimal number.

MASM assembly language

Contents
Write a program that transforms given positive integer (septenary number) into
an decimal number. Since we did not learn the input function, you have to declare a specific
variable var1 for the septenary number. After calculating decimal number, then insert that in to the
eax. At the end of your code, use DumpRegs function to check the eax value. The following figure
shows you the var1 format. (Other numbers will be used instead of 65 when scoring.)
var1 SDWORD 65
Assumption: Input values can be represented as 32-bit unsigned integers when converted to
decimal number.

Explanation / Answer

Answer to the question :-

For converting a septenary number to a decimal number let us take a small example below for proper understanding:-

Example- 123 7 to base 10(decimal number)

(12  21 30 )7 = 3 * 70 + 2 * 71 + 1* 72

= 3 + 2*7 + 7*7

= 3 + 14 + 49

= 6610

So, 1237 = 6610

As the figure(which says will show var1 format) mentioned in the question is not provided so I am assuming and scripting the code for generic conversion of a septenary number to a decimal number using MASM below :-

DATA SEGMENT ; Segment to define variables

VAR1 DW 123S ; Initializing septenary number to var1, S or s to be used for specifying number format as septenary ; else will be interpreted as decimal, DW can hold upto 4 digits.

; Let the user initialised septenary number is 123S.Any number upto 4 digits can be initialised since we are using DW

DECIMAL DB 15 DUP ('$') ;Defining array to store the decimal equivalent result. Initializing array with $.Taking the length of ;array as 15 as we don't know the length of the array.

DATA ENDS

CODE SEGMENT ; starting point

ASSUME DS:DATA_SEG, CS:CODE_SEG

START:

MOV EAX,DATA_SEG ;Initializing data segment

MOV DS,EAX

MOV EAX,VAR1 ; move the septenary number variable to register EAX

LEA DI,DECIMAL ; initialise decimal result to destination character array register

CALL SEPTTODEC

LEA DX,DECIMAL

MOV AH,9 ; Print address in DX

INT 21H ;Dos interrupt

MOV AH,4CH ;terminate current process

INT 21H ;Dos interrupt

CODE ENDS

SEPTTODEC PROC NEAR ;Call procedure within the program

MOV CX,0 ; the septenary number is to be divided till the quotient is zero.CX will store the number digit

;generated by dividing the septenary number by 10. Set counter to zero.

MOV BX,10

LOOP1: MOV DX,0

DIV BX ; EAX will store quotient and DX will store remainder

ADD DL,30H ; Add 30H in order to make it an ASCII character

PUSH DX ; temporarily store DX value to stack

INC CX ; increase counter

MOV CX,15 ; assuming user may input upto 15 digits ie max. length of array

CMP EAX, 9 ; continue dividing EAX till the value stored is greater than 9

JG LOOP1

ADD AL,30H

MOV [DI],AL ; converting the last remainder to character array and storing in array register DI

LOOP2: POP EAX

INC DI ; increment destination pointer

MOV [DI],AL

LOOP LOOP2

RET

MOV EAX, DI ; Copy contents from DI to EAX register

SEPTTODEC ENDP

END START

EAX is the full 32 it value of the register, AX is the lower 16 bit value, AL is the lower 8 bit value and AH is the value through bits 8-15

The following procedure can be called additionally to display EAX register values.

INCLUDE IRIVINE32.INC

.CODE

main PROC

CALL DumpRegs ;display general register values

EXIT

MAIN ENDP

END MAIN

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote