几道汇编入门题目(二)

继上次的三道汇编编程练习,本篇博客同样会介绍三道汇编相关编程题目

 


 

1 用汇编语言编写一个子程序,根据入口参数AL为0、12,分别实现大写字母转换为小写,
小写字母转换成大写或大小写字母互换。然后再编写主程序,通过调用该子程序把键盘输入
的字符串mystring(长度不超过20Byte)作相应转换(具体何种转换可以让用户通过键盘
输入来选择),并输出到屏幕显示。

 

Solution Code:

data segment

    buffer     db 81

            db 0

            db 81 dup('$')

ends



stack segment

            dw    128    dup(0)

ends



code segment

assume CS:code, DS:data



main proc far

            mov ax, data

            mov ds, ax

            mov es, ax



            mov ah, 0ah

            mov dx, seg buffer

            mov ds, dx

            lea dx, buffer

            int 21h



getkey:     mov ah, 1

            int 21h



            lea bx, buffer+2    ;input string

            mov ch, 0

            mov cl, buffer+1



            call func             ;call function



            lea dx, buffer+2    ;output string

            mov ah, 09h

            int 21h



            mov ax, 4c00h

            int 21h

main endp



func proc near

each:

            cmp al, '0'

            je func0

            cmp al, '1'

            je func1

            cmp al, '2'

            je func2

func0:

            cmp [bx], 'Z'    ;Judge whether not abc

            jle endf

            sub [bx], 32

            jmp endf

func1:

            cmp [bx], 'a'    ;Jedge whether not ABC

            jge endf

            add [bx], 32

            jmp endf

func2:

            cmp [bx], 'Z'

            jg func0

            jmp func1

endf:

            inc bx

            loop each

            ret

func endp



ends

end main

2 用汇编语言编写一个子程序,把一个16位二进制数用十六进制形式在屏幕上显示出来,分别运用如下3种参数传递方法,并用一个主程序验证它。

(1)    采用AX寄存器传递这个16位二进制数;

(2)    采用wordTEMP变量传递这个16位二进制数;

(3)    采用堆栈方法传递这个16位二进制数。

 

其中第二小题没有写正确,先传上来吧 :(

 

data segment

    dig dw 1010100110100011B, '$'

    tmpdig db 00, 00, 00, 00, '$'

    displayword db "     $"

    pkey db "press any key...$"

ends



stack segment

    dw 128 dup(0)

ends



code segment

main proc far

    mov ax, data

    mov ds, ax

    mov es, ax



    mov ax, dig

    call axtr        ;by register AX

    

    lea dx, displayword

    mov ah, 9

    int 21h



    call wordtmp    ;by variable wordtmp

    

    lea dx, displayword

    mov ah, 9

    int 21h



    mov ax, dig

    push ax

    mov ax, 0

    call bystack    ;by stack method



    mov ax, 4c00h

    int 21h

main endp



axtr proc near



    mov cx, 4

    mov si, 3



funcax:

    mov bx, ax

    and bx, 000Fh

    cmp bx, 0009h    ;just cmp the last bit

    jg axchar        ;jmp to axchar if it's char

    add bx, 30h        ;for ascll adjust

    jmp axsolve



axchar:

    add bx, 37h



axsolve:

    mov dx, bx

    lea bx, tmpdig

    mov [bx+si], dl    ;store current bit result

    shr ax, 4

    dec si

    loop funcax



    lea dx, tmpdig    ;display

    mov ah, 9

    int 21h

    ret



axtr endp



wordtmp proc near



    mov ax, dig

    mov cx, 4

    mov si, 3



op2:

    mov bx, ax

    and bx, 000Fh

    cmp bx, 0009h

    ja gcc3

    add bx, 30h

    jmp gcc4



gcc3:

    add bx, 37h



gcc4:

    mov dx, bx

    lea bx, tmpdig

    mov [bx+si], dl

    shr ax, 4

    dec si

    loop op2



    lea dx, tmpdig

    mov ah, 9

    int 21h

    ret



wordtmp endp



bystack proc near

    

    push bp

    mov bp, sp

    mov ax, [bp+4]

    mov cx, 4

    mov si, 3



funcstack:

    mov bx, ax

    and bx, 000Fh

    cmp bx, 0009h

    jg stackchar

    add bx, 30h

    jmp stacksolve



stackchar:

    add bx, 37h



stacksolve:

    mov dx, bx

    lea bx, tmpdig

    mov [bx+si], dl

    shr ax, 4

    dec si

    loop funcstack



    lea dx, tmpdig

    mov ah, 9

    int 21h

    pop bp

    ret



bystack endp



ends

end main

3 设数据段事先定义了一个数组存放着30位学生的成绩(0~100),
编写子程序,统计0~59分,60~69分,70~79分,80~89分,90~100分的人数,
编写主程序在屏幕上输出等级和所对应人数,例如: A:
2 B:11 C:13 D:3 E:1

 

本题还没有写完,先传上来吧 :(

 

data segment

    rst db 56, 69, 84, 82, 73, 88, 99, 63, 100, 80, '$'

    se db 0, '$'

    sd db 0, '$'

    sc db 0, '$'

    sb db 0, '$'

    sa db 0, '$'

data ends



code segment 

    assume cs:code, ds:data



start:

    mov ax, data

    mov dx, ax



    lea si, rst

    mov cx, 10



    ;lea bx, se

    ;add [bx], 1;

    ;mov ax, [bx];

    ;add ax, 30h



    ;mov ah, 02H

    ;mov dl, al

    ;int 21h



lop1:

    cmp [si], 60

    ;cmp byte ptr [si], 60

    jb five

    cmp [si], 70

    ;cmp byte ptr [si], 70

    jb six

    cmp [si], 80

    ;cmp byte ptr [si], 80

    jb seven

    cmp [si], 90

    ;cmp byte ptr [si], 90

    jb eight



    jmp nine



five:

    lea bx, se

    add [bx], 1;

    jmp lop



six:

    lea bx, sd

    add [bx], 1;

    jmp lop



seven:

    lea bx, sc

    add [bx], 1;

    jmp lop



eight:

    lea bx, sb

    add [bx], 1;

    jmp lop



nine:

    lea bx, sb

    add [bx], 1;

    jmp lop



lop:

    inc si

    loop lop1



display:

    lea bx, se

    add [bx], 30h

    mov ah, 02H

    mov dl, [bx]

    int 21h



    lea bx, sd

    add [bx], 30h

    mov ah, 02H

    mov dl, [bx]

    int 21h



    lea bx, sc

    add [bx], 30h

    mov ah, 02H

    mov dl, [bx]

    int 21h



    lea bx, sb

    add [bx], 30h

    mov ah, 02H

    mov dl, [bx]

    int 21h



    lea bx, sa

    add [bx], 30h

    mov ah, 02H

    mov dl, [bx]

    int 21h



    mov ah, 02H

    mov dl, '$'

    int 21h



exit:

    mov ah, 4ch

    int 21h



code ends

    end start

 

你可能感兴趣的:(入门)