Compute 2x (Assembly Language)

; Program to compute 2x

DATA SEGMENT ;INITIALIZE DATA SEGMENT
NUM1 DD 0.5 ;INTIALIZE NUM AS 0.5H
;NOTE IN EXAM DONT INITIALIZE NUM1 MORE THAN 0.9
;RANGE SHOULD BE 0.1-0.9H ONLY
;REASON BECAUSE THE COMMAND F2XM1 WHERE
;X SHOULD BE SPECIFIED WITHING 0 > X < 1
RES DD ? ;INITIALIZE RES
DATA ENDS ;END OF DATA SEGMENT

CODE SEGMENT ;INITIALIZE CODE SEGMENT
START: ;START THE CODE
ASSUME CS:CODE,DS:DATA ;ASSUMPTION OF CODE AND DATA
MOV AX,DATA ;MOVE DATA INTO ACCUMULATOR AX REGISTER
MOV DS,AX ;MOVE AX INTO DATA SEGMENT REGISTER DS
FINIT ;INITIALIZE THE STACK
FLD NUM1 ;LOAD EFFECTIVE NUMBER
F2XM1 ;PERFROM 2X MINUS 1
FSTP RES ;POP THE RESULT FROM TOP OF THE STACK
MOV AH,4CH ;END OF CODE
INT 21H ;END OF CODE
CODE ENDS ;END OF CODE SEGMENT
END START ;END OF START
;INPUT
; NUM1 – 0.5H

;TO VIEW THE OUTPUT GO TO DUMP AND OPEN NUMERIC PROCESSOR
;AT THE START OT THE PROGRAM BEFORE TRACING THE PROGRAM USING F7

;OUTPUT
; RES – 0.414212h

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s