Skip to main content

Program 3: Find the Maximum of Two Numbers

 **Program 3: Find the Maximum of Two Numbers**


```assembly

.model small

.stack 100h


.data

    num1 dw 5

    num2 dw 7

    result dw ?


.code

    main proc

        mov ax, num1        ; Load first number into AX

        cmp ax, num2        ; Compare with second number

        jge greater         ; Jump to greater if AX >= num2

        

        mov ax, num2        ; Load second number into AX

        jmp end_prog

        

    greater:

        mov ax, num1


    end_prog:

        mov result, ax      ; Store result in 'result'

        

        mov ah, 4Ch         ; Exit program

        int 21h

    main endp

end main

```


Explanation:

1. `.model small` and `.stack 100h`: Memory model and stack size definitions.

2. `.data` section: Declares the data segment.

   - `num1 dw 5`: Defines a word-sized variable named "num1" with value 5.

   - `num2 dw 7`: Defines a word-sized variable named "num2" with value 7.

   - `result dw ?`: Defines a word-sized uninitialized variable named "result".

3. `.code` section: Contains the main code.

   - `mov ax, num1`: Move the value of "num1" into the AX register.

   - `cmp ax, num2`: Compare the value in AX with the value in "num2".

   - `jge greater`: Jump to the "greater" label if AX is greater than or equal to "num2".

   - `mov ax, num2`: Move the value of "num2" into AX (if AX is not greater).

   - `jmp end_prog`: Unconditional jump to the "end_prog" label.

   - `greater:`: Label for the case when the first number is greater.

   - `mov ax, num1`: Move the value of "num1" into AX.

   - `end_prog:`: Label for the end of the program.

   - `mov result, ax`: Store the result in the "result" variable.

   - `mov ah, 4Ch`: Set the exit code for DOS.

   - `int 21h`: Call DOS interrupt to exit the program.


Comments

Popular posts from this blog

Program 6: Finding Prime Numbers in a Range

  ** Program 6: Finding Prime Numbers in a Range ** ```assembly .model small .stack 100h .data     start dw 1     end dw 20 .code     main proc         mov ax, start           ; Load 'start' into AX              find_primes:         inc ax                  ; Move to the next number         cmp ax, end             ; Compare with 'end'         jg end_prog             ; Jump to end if AX > 'end'                  mov cx, ax              ; Copy AX to CX   ...

4. Write a LEX Program to convert the substring abc to ABC from the given input string.

Sure, here's a LEX program that converts the substring "abc" to "ABC" in the given input string: ```lex %{ #include <stdio.h> %} %% .*abc.*    { printf("%s", yytext); }    /* Match and print everything containing 'abc' */ .         ;                            /* Ignore other characters */ %% int main() {     yylex();     return 0; } ``` Now, let's break down the code line by line: 1. `%{` and `%}`: These are used to enclose C code that should be included in the generated C code. In this case, it includes the standard input-output library (`<stdio.h>`). 2. `.*abc.*`: This is a regular expression pattern. It matches any sequence of characters that contains the substring "abc". 3. `{ printf("%s", yytext); }`: This is the action associated with the pattern. When the pattern is matched, the `yytext` variable contains the matched te...

ktu 2019 Cse Complier programing Lab Syllabus

 1Design and implement a lexical analyzer using C language to recognize all valid tokens  in the input program. The lexical analyzer should ignore redundant spaces, tabs and  newlines. It should also ignore comments. 2. Implement a Lexical Analyzer for a given program using Lex Tool. 3. Write a lex program to display the number of lines, words and characters in an input text. 4. Write a LEX Program to convert the substring abc to ABC from the given input string. 5. Write a lex program to find out the total number of vowels and consonants from the given  input string. 6. Generate a YACC specification to recognize a valid arithmetic expression that uses  operators +, – , *,/ and parenthesis. 7. Generate a YACC specification to recognize a valid identifier which starts with a letter  followed by any number of letters or digits.   8. Implementation of Calculator using LEX and YACC  9. Convert the BNF rules into YACC form and write code to generat...